diff --git a/OAT.xml b/OAT.xml
index 5d8a8bd5c8e86805323a9003b823bb53ea96c367..2b4d5172eb49860fad4b14adbb8191d232159f7c 100644
--- a/OAT.xml
+++ b/OAT.xml
@@ -170,6 +170,9 @@ Note:If the text contains special characters, please escape them according to th
+
+
+
diff --git a/code/ArkTS1.2/ANISample/.gitignore b/code/ArkTS1.2/ANISample/.gitignore
index d2ff20141ceed86d87c0ea5d99481973005bab2b..6efa5f5bcfa976d4c7f8b4ff3f614a4e05b80c34 100644
--- a/code/ArkTS1.2/ANISample/.gitignore
+++ b/code/ArkTS1.2/ANISample/.gitignore
@@ -9,4 +9,4 @@
/.clang-format
/.clang-tidy
**/.test
-/.appanalyzer
\ No newline at end of file
+/.appanalyzer
diff --git a/code/ArkTS1.2/ANISample/README.md b/code/ArkTS1.2/ANISample/README.md
new file mode 100644
index 0000000000000000000000000000000000000000..f4ec5724cdcf0f2865dcae018810fb6ca1ea4ce3
--- /dev/null
+++ b/code/ArkTS1.2/ANISample/README.md
@@ -0,0 +1,135 @@
+# ArkTs和C++互相调用
+
+### 介绍
+
+如下需求和场景的相互调用:ArkTS 2.0原生接口(类型API)ArkTS 2.0原生接口(对象API)ArkTS 2.0原生接口(VM API)
+
+### 效果预览
+
+效果如下所示:
+
+|主页|主页|主页|
+|--------------------------------|---------------------------------|--------------------------------|
+||||
+
+使用说明
+
+1. 在主界面,优先点击蓝色按钮'loadAniTest'加载ani动态库;
+2. 依次点击其余按钮会在对应下方预期结果部分打印出对应日志;
+
+
+### 工程目录
+
+```
+entry/src/main
+|---cpp
+| |---ani_accessing_fields.cpp // 成员属性/静态成员案例
+| |---ani_array.cpp // 数组案例
+| |---ani_calling_methods.cpp // 方法回调/静态方法案例
+| |---ani_class_operation.cpp // 类案例
+| |---ani_error.cpp // 异常机制案例
+| |---ani_init.cpp // ani方法绑定
+| |---ani_object.cpp // 对象案例
+| |---ani_promise.cpp // 异步案例
+| |---ani_references.cpp // 全局/局部/弱引用创建案例
+| |---ani_reflection.cpp // 反射机制
+| |---ani_string.cpp // 字符串案例
+| |---ani_versionInfo.cpp // 版本信息
+| |---ani_vminterface.cpp // 虚接口案例
+| |---CMakeLists.txt
+|---ets
+| |---pages
+| | |---index.ets // 首页
+```
+
+### 具体实现
+
+* VM Interface 源码参考: [ani_vminterface.cpp](entry/src/main/cpp/ani_vminterface.cpp)
+ * 调用[VMInterface()](entry/src/main/cpp/ani_vminterface.cpp)函数检索虚拟机(VM)实例。
+* Version Info 源码参考: [ani_versionInfo.cpp](entry/src/main/cpp/ani_versionInfo.cpp)
+ * 调用[GetVersionInfo()](entry/src/main/cpp/ani_versionInfo.cpp)函数获取版本信息。
+* Global and Local References 源码参考: [ani_references.cpp](entry/src/main/cpp/ani_references.cpp)
+ * 调用[Global_Local_References()](entry/src/main/cpp/ani_references.cpp)函数创建一个全局引用,成功创建后销毁。
+* Weak Global References 源码参考: [ani_references.cpp](entry/src/main/cpp/ani_references.cpp)
+ * 调用[Weak_Global_References()](entry/src/main/cpp/ani_references.cpp)函数创建一个弱引用,成功创建后销毁。
+* String Operations 源码参考: [ani_string.cpp](entry/src/main/cpp/ani_string.cpp)
+ * 调用[String_Operations()](entry/src/main/cpp/ani_string.cpp)函数将字符串返回到ArkTS。
+* Promise 源码参考: [ani_promise.cpp](entry/src/main/cpp/ani_promise.cpp)
+ * 调用[startAbility()](entry/src/main/cpp/ani_promise.cpp)函数异步调用日志会打印线程ID,同时返回指定数字判断是否为预定数字,相同则测试通过,否则返回失败。
+* Array Operations 源码参考: [ani_array.cpp](entry/src/main/cpp/ani_array.cpp)
+ * 调用[ProcessArray()](entry/src/main/cpp/ani_array.cpp)函数创建基础数据并返回创建是否成功的布尔值到ArkTS。
+ * 调用[ProcessArray2()](entry/src/main/cpp/ani_array.cpp)函数创建剩余基础数据并返回创建是否成功的布尔值到ArkTS。
+* Object Operations 源码参考: [ani_object.cpp](entry/src/main/cpp/ani_object.cpp)
+ * 调用[HandleDoubleData()](entry/src/main/cpp/ani_object.cpp)函数创建ani_object对象将传入数据绑定到该对象上,检查对象是否是指定类型的实例,同时返回传入的值。
+* Exceptions 源码参考: [ani_error.cpp](entry/src/main/cpp/ani_error.cpp)
+ * 调用[ThrowError()](entry/src/main/cpp/ani_error.cpp)函数抛出ArkTs创建的错误类信息。
+* Reflection Support 源码参考: [ani_reflection.cpp](entry/src/main/cpp/ani_reflection.cpp)
+ * 调用[CreatePerson()](entry/src/main/cpp/ani_reflection.cpp)函数创建ArkTs侧对象同时调用Object_SetPropertyByName_Int()和Object_SetPropertyByName_Ref()对继承的接口成员属性赋值并返回。
+ * 调用[BindSet()](entry/src/main/cpp/ani_reflection.cpp)函数对ArkTs侧成员变量赋值。
+ * 调用[BindGet()](entry/src/main/cpp/ani_reflection.cpp)函数获取ArkTs侧成员变量并返回。
+* Accessing Static Fields 源码参考: [ani_accessing_fields.cpp](entry/src/main/cpp/ani_accessing_fields.cpp)
+ * 调用[UpdateStaticFields()](entry/src/main/cpp/ani_accessing_fields.cpp)函数调用ArkTs侧静态成员变量并从C++侧赋值。
+ * 调用[UpdateStaticFields2()](entry/src/main/cpp/ani_accessing_fields.cpp)函数调用ArkTs侧静态成员变量并从C++侧赋值。
+ * 调用[GetStaticFields()](entry/src/main/cpp/ani_accessing_fields.cpp)函数可从ArkTS类中获取静态成员的值。
+ * 调用[GetStaticFields2()](entry/src/main/cpp/ani_accessing_fields.cpp)函数可从ArkTS类中获取静态成员的值。
+* Accessing Fields Of Objects 源码参考: [ani_accessing_fields.cpp](entry/src/main/cpp/ani_accessing_fields.cpp)
+ * 调用[UpdateFields()](entry/src/main/cpp/ani_accessing_fields.cpp)函数调用ArkTs侧通过类名并且查询成员名称字段后,调用ani方法Object_SetField_XX()从C++侧赋值。
+ * 调用[UpdateField2()](entry/src/main/cpp/ani_accessing_fields.cpp)函数调用ArkTs侧通过类名并且查询成员名称字段后,调用ani方法Object_SetField_XX()从C++侧赋值。
+ * 调用[UpdateByNameFields()](entry/src/main/cpp/ani_accessing_fields.cpp)函数调用ArkTs侧通过查找成员变量名称直接从C++侧赋值。
+ * 调用[UpdateByNameFields2()](entry/src/main/cpp/ani_accessing_fields.cpp)函数调用ArkTs侧通过查找成员变量名称直接从C++侧赋值。
+* Class Operations 源码参考: [ani_class_operation.cpp](entry/src/main/cpp/ani_class_operation.cpp)
+ * 调用[NativeVoidFunc()](entry/src/main/cpp/ani_class_operation.cpp)函数中先通过FindClass()寻找ArkTs的类,调用Class_FindMethod()通过方法的名称和签名查找方法,使用Object_CallMethod_Void()方法回调触发ArkTs的另一函数并不带返回值。
+ * 调用[NativeBoolFunc()](entry/src/main/cpp/ani_class_operation.cpp)函数中先通过FindClass()寻找ArkTs的类,调用Class_FindMethod()通过方法的名称和签名查找方法,然后使用Object_CallMethod_Boolean()方法回调触发ArkTs的另一函数并带返回值,返回值类型为boolean,将返回值返回给ani的绑定函数。
+ * 调用[NativeIntFunc()](entry/src/main/cpp/ani_class_operation.cpp)函数中使用Object_CallMethod_Int()方法回调触发ArkTs的另一函数并带返回值,返回值类型为int,将返回值返回给ani的绑定函数。
+ * 调用[NativeShortFunc()](entry/src/main/cpp/ani_class_operation.cpp)函数中先通过FindClass()寻找ArkTs的类,调用Class_FindMethod()通过方法的名称和签名查找方法,使用Object_CallMethod_Short()方法回调触发ArkTs的另一函数并带返回值,返回值类型为short,将返回值返回给ani的绑定函数。
+ * 调用[NativeLongFunc()](entry/src/main/cpp/ani_class_operation.cpp)函数中先通过FindClass()寻找ArkTs的类,调用Class_FindMethod()通过方法的名称和签名查找方法,使用Object_CallMethod_Long()方法回调触发ArkTs的另一函数并带返回值,返回值类型为long,将返回值返回给ani的绑定函数。
+ * 调用[NativeDoubleFunc()](entry/src/main/cpp/ani_class_operation.cpp)函数中先通过FindClass()寻找ArkTs的类,调用Class_FindMethod()通过方法的名称和签名查找方法,使用Object_CallMethod_Double()方法回调触发ArkTs的另一函数并带返回值,返回值类型为double,将返回值返回给ani的绑定函数。
+ * 调用[NativeFloatFunc()](entry/src/main/cpp/ani_class_operation.cpp)函数中先通过FindClass()寻找ArkTs的类,调用Class_FindMethod()通过方法的名称和签名查找方法,使用Object_CallMethod_Float()方法回调触发ArkTs的另一函数并带返回值,返回值类型为float,将返回值返回给ani的绑定函数。
+ * 调用[NativeCharFunc()](entry/src/main/cpp/ani_class_operation.cpp)函数中先通过FindClass()寻找ArkTs的类,调用Class_FindMethod()通过方法的名称和签名查找方法,使用Object_CallMethod_Char()方法回调触发ArkTs的另一函数并带返回值,返回值类型为char,将返回值返回给ani的绑定函数。
+ * 调用[NativeByteFunc()](entry/src/main/cpp/ani_class_operation.cpp)函数中先通过FindClass()寻找ArkTs的类,调用Class_FindMethod()通过方法的名称和签名查找方法,使用Object_CallMethod_Byte()方法回调触发ArkTs的另一函数并带返回值,返回值类型为byte,将返回值返回给ani的绑定函数。
+* Calling Instance Methods 源码参考: [ani_calling_methods.cpp](entry/src/main/cpp/ani_calling_methods.cpp)
+ * 调用[NativeByNameFunc()](entry/src/main/cpp/ani_calling_methods.cpp)函数中直接使用Object_CallMethodByName_Void()方法回调触发ArkTs的另一函数不带返回值。
+ * 调用[NativeByNameDoubleFunc()](entry/src/main/cpp/ani_calling_methods.cpp)函数中直接使用Object_CallMethodByName_Double()方法回调触发ArkTs的另一函数带返回值,返回值类型为double,将返回值返回给ani的绑定函数。
+ * 调用[NativeByNameBoolFunc()](entry/src/main/cpp/ani_calling_methods.cpp)函数中直接使用Object_CallMethodByName_Boolean()方法回调触发ArkTs的另一函数带返回值,返回值类型为boolean,将返回值返回给ani的绑定函数。
+ * 调用[NativeByNameIntFunc()](entry/src/main/cpp/ani_calling_methods.cpp)函数中直接使用Object_CallMethodByName_Int()方法回调触发ArkTs的另一函数带返回值,返回值类型为int,将返回值返回给ani的绑定函数。
+ * 调用[NativeByNameShortFunc()](entry/src/main/cpp/ani_calling_methods.cpp)函数中直接使用Object_CallMethodByName_Short()方法回调触发ArkTs的另一函数带返回值,返回值类型为short,将返回值返回给ani的绑定函数。
+ * 调用[NativeByNameLongFunc()](entry/src/main/cpp/ani_calling_methods.cpp)函数中直接使用Object_CallMethodByName_Long()方法回调触发ArkTs的另一函数带返回值,返回值类型为long,将返回值返回给ani的绑定函数。
+ * 调用[NativeByNameCharFunc()](entry/src/main/cpp/ani_calling_methods.cpp)函数中直接使用Object_CallMethodByName_Char()方法回调触发ArkTs的另一函数带返回值,返回值类型为char,将返回值返回给ani的绑定函数。
+ * 调用[NativeByNameFloatFunc()](entry/src/main/cpp/ani_calling_methods.cpp)函数中直接使用Object_CallMethodByName_Boolean()方法回调触发ArkTs的另一函数带返回值,返回值类型为float,将返回值返回给ani的绑定函数。
+ * 调用[NativeByNameByteFunc()](entry/src/main/cpp/ani_calling_methods.cpp)函数中直接使用Object_CallMethodByName_Byte()方法回调触发ArkTs的另一函数带返回值,返回值类型为byte,将返回值返回给ani的绑定函数。
+* Calling Static Methods 源码参考: [ani_calling_methods.cpp](entry/src/main/cpp/ani_calling_methods.cpp)
+ * 调用[NativeStaticFunc()](entry/src/main/cpp/ani_calling_methods.cpp)函数中先通过FindClass()寻找ArkTs的类,调用Class_FindStaticMethod()通过方法的名称和签名查找静态方法,使用Class_CallStaticMethod_Void()方法回调触发ArkTs的另一函数不带返回值。
+ * 调用[NativeStaticFuncDouble()](entry/src/main/cpp/ani_calling_methods.cpp)函数中先通过FindClass()寻找ArkTs的类,调用Class_FindStaticMethod()通过方法的名称和签名查找静态方法,使用Class_CallStaticMethod_Double()方法回调触发ArkTs的另一函数带返回值,返回值类型为double,将返回值返回给ani的绑定函数。
+ * 调用[NativeStaticFuncFloat()](entry/src/main/cpp/ani_calling_methods.cpp)函数中先通过FindClass()寻找ArkTs的类,调用Class_FindStaticMethod()通过方法的名称和签名查找静态方法,使用Class_CallStaticMethod_Float()方法回调触发ArkTs的另一函数带返回值,返回值类型为float,将返回值返回给ani的绑定函数。
+ * 调用[NativeStaticFuncChar()](entry/src/main/cpp/ani_calling_methods.cpp)函数中先通过FindClass()寻找ArkTs的类,调用Class_FindStaticMethod()通过方法的名称和签名查找静态方法,使用Class_CallStaticMethod_Char()方法回调触发ArkTs的另一函数带返回值,返回值类型为char,将返回值返回给ani的绑定函数。
+ * 调用[NativeStaticFuncByte()](entry/src/main/cpp/ani_calling_methods.cpp)函数中先通过FindClass()寻找ArkTs的类,调用Class_FindStaticMethod()通过方法的名称和签名查找静态方法,使用Class_CallStaticMethod_Byte()方法回调触发ArkTs的另一函数带返回值,返回值类型为byte,将返回值返回给ani的绑定函数。
+ * 调用[NativeStaticFuncBoolean()](entry/src/main/cpp/ani_calling_methods.cpp)函数中先通过FindClass()寻找ArkTs的类,调用Class_FindStaticMethod()通过方法的名称和签名查找静态方法,使用Class_CallStaticMethod_Boolean()方法回调触发ArkTs的另一函数带返回值,返回值类型为boolean,将返回值返回给ani的绑定函数。
+ * 调用[NativeStaticFuncInt()](entry/src/main/cpp/ani_calling_methods.cpp)函数中先通过FindClass()寻找ArkTs的类,调用Class_FindStaticMethod()通过方法的名称和签名查找静态方法,使用Class_CallStaticMethod_Int()方法回调触发ArkTs的另一函数带返回值,返回值类型为int,将返回值返回给ani的绑定函数。
+ * 调用[NativeStaticFuncShort()](entry/src/main/cpp/ani_calling_methods.cpp)函数中先通过FindClass()寻找ArkTs的类,调用Class_FindStaticMethod()通过方法的名称和签名查找静态方法,使用Class_CallStaticMethod_Short()方法回调触发ArkTs的另一函数带返回值,返回值类型为short,将返回值返回给ani的绑定函数。
+ * 调用[NativeStaticFuncLong()](entry/src/main/cpp/ani_calling_methods.cpp)函数中先通过FindClass()寻找ArkTs的类,调用Class_FindStaticMethod()通过方法的名称和签名查找静态方法,使用Class_CallStaticMethod_Long()方法回调触发ArkTs的另一函数带返回值,返回值类型为long,将返回值返回给ani的绑定函数。
+ * Promise 源码参考: [ani_promise.cpp](entry/src/main/cpp/ani_promise.cpp)
+ ### 相关权限
+
+无
+
+### 依赖
+
+无
+
+### 约束与限制
+
+1. 本示例仅支持标准系统上运行,支持设备:Phone;
+2. 本示例为Stage模型,支持API20版本SDK,SDK版本号(API Version 20),镜像版本号(6.0.0.31)。
+3. 本示例需要使用DevEco Studio 版本号(6.0.0.6)版本才可编译运行。
+
+### 下载
+
+如需单独下载本工程,执行如下命令:
+
+```
+git init
+git config core.sparsecheckout true
+echo code/ArkTS1.2/ANISample/ > .git/info/sparse-checkout
+git remote add origin https://gitee.com/openharmony/applications_app_samples.git
+git pull
+```
\ No newline at end of file
diff --git a/code/ArkTS1.2/ANISample/build-profile.json5 b/code/ArkTS1.2/ANISample/build-profile.json5
index 6a325164e4f9f873bcb884a635ef0e36a15a06cc..7178fe08b386249b64b2c1afbd1e9844aa959548 100644
--- a/code/ArkTS1.2/ANISample/build-profile.json5
+++ b/code/ArkTS1.2/ANISample/build-profile.json5
@@ -5,9 +5,9 @@
{
"name": "default",
"signingConfig": "default",
- "compatibleSdkVersion": "5.0.2(14)",
- "runtimeOS": "HarmonyOS",
"arkTSVersion": "1.2",
+ "compatibleSdkVersion": "6.0.0(20)",
+ "runtimeOS": "HarmonyOS",
"buildOption": {
"strictMode": {
"caseSensitiveCheck": true,
@@ -37,6 +37,6 @@
]
}
]
- },
+ }
]
}
\ No newline at end of file
diff --git a/code/ArkTS1.2/ANISample/entry/build-profile.json5 b/code/ArkTS1.2/ANISample/entry/build-profile.json5
index 48bbe2b7d7b95e4d6f4ee0741a8c6c088a13609b..38bdcc9929e2c5bd7f51c4fc96a398ccebd0d6ce 100644
--- a/code/ArkTS1.2/ANISample/entry/build-profile.json5
+++ b/code/ArkTS1.2/ANISample/entry/build-profile.json5
@@ -1,6 +1,5 @@
{
"apiType": "stageMode",
- "arkTSVersion": "1.2",
"buildOption": {
"externalNativeOptions": {
"path": "./src/main/cpp/CMakeLists.txt",
@@ -20,6 +19,12 @@
]
}
}
+ },
+ "nativeLib": {
+ "debugSymbol": {
+ "strip": true,
+ "exclude": []
+ }
}
},
],
diff --git a/code/ArkTS1.2/ANISample/entry/src/main/cpp/CMakeLists.txt b/code/ArkTS1.2/ANISample/entry/src/main/cpp/CMakeLists.txt
index 98943cf74cccc3f98d0a8f276cd697c55c9be6c2..498914564d48fb56a49a77a936e8b504b7314742 100644
--- a/code/ArkTS1.2/ANISample/entry/src/main/cpp/CMakeLists.txt
+++ b/code/ArkTS1.2/ANISample/entry/src/main/cpp/CMakeLists.txt
@@ -10,5 +10,5 @@ endif()
include_directories(${NATIVERENDER_ROOT_PATH}
${NATIVERENDER_ROOT_PATH}/include)
-add_library(entry SHARED ani_init.cpp)
-target_link_libraries(entry PUBLIC libhilog_ndk.z.so)
\ No newline at end of file
+add_library(aniTest SHARED ani_init.cpp)
+target_link_libraries(aniTest PUBLIC libhilog_ndk.z.so)
\ No newline at end of file
diff --git a/code/ArkTS1.2/ANISample/entry/src/main/cpp/ani_accessing_fields.cpp b/code/ArkTS1.2/ANISample/entry/src/main/cpp/ani_accessing_fields.cpp
index 794f49807d56eadb622e0d812d2d767d18b37aee..b3645e57de3ece36ad05f76257e3f930e77975d1 100644
--- a/code/ArkTS1.2/ANISample/entry/src/main/cpp/ani_accessing_fields.cpp
+++ b/code/ArkTS1.2/ANISample/entry/src/main/cpp/ani_accessing_fields.cpp
@@ -25,7 +25,6 @@
*/
#include "ani/ani.h"
-#include "hilog/log.h"
#include
#define CHAR_A 'A'
@@ -46,16 +45,11 @@
#define NUM15_2365941 15.2365941
#define NUM12365478941 12365478941
-#undef LOG_DOMAIN
-#undef LOG_TAG
-#define LOG_DOMAIN 0x3200 // 全局domain宏,标识业务领域
-#define LOG_TAG "MY_TAG" // 全局tag宏,标识模块日志tag
-
// Accessing Fields of Objects Class Operations
static void UpdateFields(ani_env *env, ani_object obj)
{
std::cout << "Update Field in native" << std::endl;
- const char *className = "Lentry/src/main/ets/entryability/EntryAbility/Calc;";
+ const char *className = "Lentry/src/main/ets/pages/Index/Calc;";
ani_class cls;
if (ANI_OK != env->FindClass(className, &cls)) {
std::cerr << "Not found '" << className << "'" << std::endl;
@@ -97,13 +91,12 @@ static void UpdateFields(ani_env *env, ani_object obj)
if (ANI_OK != env->Object_SetField_Char(obj, charField, charValue)) {
std::cerr << "Set Field Fail" << className << "'" << std::endl;
}
- return;
}
static void UpdateFields2(ani_env *env, ani_object obj)
{
std::cout << "Update Field in native" << std::endl;
- const char *className = "Lentry/src/main/ets/entryability/EntryAbility/Calc;";
+ const char *className = "Lentry/src/main/ets/pages/Index/Calc;";
ani_class cls;
if (ANI_OK != env->FindClass(className, &cls)) {
std::cerr << "Not found '" << className << "'" << std::endl;
@@ -147,94 +140,13 @@ static void UpdateFields2(ani_env *env, ani_object obj)
}
}
-static ani_int UpdateIntFields([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object obj)
-{
- ani_int intField;
- if (ANI_OK != env->Object_GetFieldByName_Int(obj, "getIntField", &intField)) {
- std::cerr << "Get Field Fail" << std::endl;
- return 0;
- }
- return intField;
-}
-
-static ani_double UpdateDoubleFields([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object obj)
-{
- ani_double doubleField;
- if (ANI_OK != env->Object_GetFieldByName_Double(obj, "getDoubleField", &doubleField)) {
- std::cerr << "Get Field Fail" << std::endl;
- return 0.0;
- }
- return doubleField;
-}
-
-static ani_boolean UpdateBoolFields([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object obj)
-{
- ani_boolean boolField;
- if (ANI_OK != env->Object_GetFieldByName_Boolean(obj, "getBoolField", &boolField)) {
- std::cerr << "Get Field Fail" << std::endl;
- return false;
- }
- return boolField;
-}
-
-static ani_short UpdateShortFields([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object obj)
-{
- ani_short shortField;
- if (ANI_OK != env->Object_GetFieldByName_Short(obj, "getShortField", &shortField)) {
- std::cerr << "Get Field Fail" << std::endl;
- return 0;
- }
- return shortField;
-}
-
-static ani_long UpdateLongFields([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object obj)
-{
- ani_long longField;
- if (ANI_OK != env->Object_GetFieldByName_Long(obj, "getLongField", &longField)) {
- std::cerr << "Get Field Fail" << std::endl;
- return 0;
- }
- return longField;
-}
-
-static ani_char UpdateCharFields([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object obj)
-{
- ani_char charField;
- if (ANI_OK != env->Object_GetFieldByName_Char(obj, "getCharField", &charField)) {
- std::cerr << "Get Field Fail" << std::endl;
- return 0;
- }
- return charField;
-}
-
-static ani_float UpdateFloatFields([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object obj)
-{
- ani_float floatField;
- if (ANI_OK != env->Object_GetFieldByName_Float(obj, "getFloatField", &floatField)) {
- std::cerr << "Get Field Fail" << std::endl;
- return 0.0;
- }
- return floatField;
-}
-
-static ani_byte UpdateByteFields([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object obj)
-{
- ani_byte byteField;
- if (ANI_OK != env->Object_GetFieldByName_Byte(obj, "getByteField", &byteField)) {
- std::cerr << "Get Field Fail" << std::endl;
- return 0x0;
- }
- return byteField;
-}
-
static void UpdateByNameFields(ani_env *env, ani_object obj)
{
std::cout << "Update Field in native" << std::endl;
- const char *className = "Lentry/src/main/ets/entryability/EntryAbility/Calc;";
+ const char *className = "Lentry/src/main/ets/pages/Index/Calc;";
ani_class cls;
if (ANI_OK != env->FindClass(className, &cls)) {
std::cerr << "Not found '" << className << "'" << std::endl;
- return;
}
ani_byte byteValue = CHAR_B;
if (ANI_OK != env->Object_SetFieldByName_Byte(obj, "fieldByName_Byte", byteValue)) {
@@ -252,17 +164,15 @@ static void UpdateByNameFields(ani_env *env, ani_object obj)
if (ANI_OK != env->Object_SetFieldByName_Boolean(obj, "fieldByName_Bool", boolValue)) {
std::cerr << "Set Field Fail" << className << "'" << std::endl;
}
- return;
}
static void UpdateByNameFields2(ani_env *env, ani_object obj)
{
std::cout << "Update Field in native" << std::endl;
- const char *className = "Lentry/src/main/ets/entryability/EntryAbility/Calc;";
+ const char *className = "Lentry/src/main/ets/pages/Index/Calc;";
ani_class cls;
if (ANI_OK != env->FindClass(className, &cls)) {
std::cerr << "Not found '" << className << "'" << std::endl;
- return;
}
ani_float floatValue = NUM15_23;
if (ANI_OK != env->Object_SetFieldByName_Float(obj, "fieldByName_Float", floatValue)) {
@@ -280,14 +190,13 @@ static void UpdateByNameFields2(ani_env *env, ani_object obj)
if (ANI_OK != env->Object_SetFieldByName_Int(obj, "fieldByName_Int", intValue)) {
std::cerr << "Set Field Fail" << className << "'" << std::endl;
}
- return;
}
// Accessing Static Fields Class Operations
static void UpdateStaticFields(ani_env *env, ani_object obj)
{
std::cout << "Update Field in native" << std::endl;
- const char *className = "Lentry/src/main/ets/entryability/EntryAbility/Calc;";
+ const char *className = "Lentry/src/main/ets/pages/Index/Calc;";
ani_class cls;
if (ANI_OK != env->FindClass(className, &cls)) {
std::cerr << "Not found '" << className << "'" << std::endl;
@@ -335,7 +244,7 @@ static void UpdateStaticFields(ani_env *env, ani_object obj)
static void UpdateStaticFields2(ani_env *env, ani_object obj)
{
std::cout << "Update Field in native" << std::endl;
- const char *className = "Lentry/src/main/ets/entryability/EntryAbility/Calc;";
+ const char *className = "Lentry/src/main/ets/pages/Index/Calc;";
ani_class cls;
if (ANI_OK != env->FindClass(className, &cls)) {
std::cerr << "Not found '" << className << "'" << std::endl;
@@ -380,106 +289,98 @@ static void UpdateStaticFields2(ani_env *env, ani_object obj)
return;
}
-static void GetStaticFields(ani_env *env, ani_object obj)
+static ani_boolean GetStaticFields(ani_env *env, ani_object obj)
{
std::cout << "Get Field in native" << std::endl;
- const char *className = "Lentry/src/main/ets/entryability/EntryAbility/Calc;";
+ const char *className = "Lentry/src/main/ets/pages/Index/Calc;";
ani_class cls;
if (ANI_OK != env->FindClass(className, &cls)) {
std::cerr << "Not found '" << className << "'" << std::endl;
- return;
+ return false;
}
ani_static_field intField;
if (ANI_OK != env->Class_FindStaticField(cls, "intStaticField", &intField)) {
std::cerr << "Get StaticField Fail" << className << "'" << std::endl;
- return;
+ return false;
}
ani_static_field shortField;
if (ANI_OK != env->Class_FindStaticField(cls, "shortStaticField", &shortField)) {
std::cerr << "Get StaticField Fail" << className << "'" << std::endl;
- return;
+ return false;
}
ani_static_field longField;
if (ANI_OK != env->Class_FindStaticField(cls, "longStaticField", &longField)) {
std::cerr << "Get StaticField Fail" << className << "'" << std::endl;
- return;
+ return false;
}
ani_static_field charField;
if (ANI_OK != env->Class_FindStaticField(cls, "charStaticField", &charField)) {
std::cerr << "Get StaticField Fail" << className << "'" << std::endl;
- return;
+ return false;
}
ani_int intValue;
if (ANI_OK != env->Class_GetStaticField_Int(cls, intField, &intValue)) {
std::cerr << "Set StaticField Fail " << className << "'" << std::endl;
}
- OH_LOG_ERROR(LOG_APP, "testTag Class_GetStaticField_Int result: %{public}d", intValue);
ani_short shortValue;
if (ANI_OK != env->Class_GetStaticField_Short(cls, shortField, &shortValue)) {
std::cerr << "Set StaticField Fail " << className << "'" << std::endl;
}
- OH_LOG_ERROR(LOG_APP, "testTag Class_GetStaticField_Short result: %{public}h", shortValue);
ani_long longValue;
if (ANI_OK != env->Class_GetStaticField_Long(cls, longField, &longValue)) {
std::cerr << "Set StaticField Fail " << className << "'" << std::endl;
}
- OH_LOG_ERROR(LOG_APP, "testTag Class_GetStaticField_Long result: %{public}l", longValue);
ani_char charValue;
if (ANI_OK != env->Class_GetStaticField_Char(cls, charField, &charValue)) {
std::cerr << "Set StaticField Fail " << className << "'" << std::endl;
}
- OH_LOG_ERROR(LOG_APP, "testTag Class_GetStaticField_Char result: %{public}c", charValue);
- return;
+ return true;
}
-static void GetStaticFields2(ani_env *env, ani_object obj)
+static ani_boolean GetStaticFields2(ani_env *env, ani_object obj)
{
std::cout << "Get Field in native" << std::endl;
- const char *className = "Lentry/src/main/ets/entryability/EntryAbility/Calc;";
+ const char *className = "Lentry/src/main/ets/pages/Index/Calc;";
ani_class cls;
if (ANI_OK != env->FindClass(className, &cls)) {
std::cerr << "Not found '" << className << "'" << std::endl;
- return;
+ return false;
}
ani_static_field byteField;
if (ANI_OK != env->Class_FindStaticField(cls, "byteStaticField", &byteField)) {
std::cerr << "Get StaticField Fail" << className << "'" << std::endl;
- return;
+ return false;
}
ani_static_field doubleField;
if (ANI_OK != env->Class_FindStaticField(cls, "doubleStaticField", &doubleField)) {
std::cerr << "Get StaticField Fail" << className << "'" << std::endl;
- return;
+ return false;
}
ani_static_field floatField;
if (ANI_OK != env->Class_FindStaticField(cls, "floatStaticField", &floatField)) {
std::cerr << "Get StaticField Fail" << className << "'" << std::endl;
- return;
+ return false;
}
ani_static_field boolField;
if (ANI_OK != env->Class_FindStaticField(cls, "boolStaticField", &boolField)) {
std::cerr << "Get StaticField Fail" << className << "'" << std::endl;
- return;
+ return false;
}
ani_byte byteValue;
if (ANI_OK != env->Class_GetStaticField_Byte(cls, byteField, &byteValue)) {
std::cerr << "Set StaticField Fail " << className << "'" << std::endl;
}
- OH_LOG_ERROR(LOG_APP, "testTag Class_GetStaticField_Byte result: %{public}c", byteValue);
ani_double doubleValue;
if (ANI_OK != env->Class_GetStaticField_Double(cls, doubleField, &doubleValue)) {
std::cerr << "Set StaticField Fail " << className << "'" << std::endl;
}
- OH_LOG_ERROR(LOG_APP, "testTag Class_GetStaticField_Double result: %{public}lf", doubleValue);
ani_boolean boolValue;
if (ANI_OK != env->Class_GetStaticField_Boolean(cls, boolField, &boolValue)) {
std::cerr << "Set StaticField Fail " << className << "'" << std::endl;
}
- OH_LOG_ERROR(LOG_APP, "testTag Class_GetStaticField_Boolean result: %{public}d", static_cast(boolValue));
ani_float floatValue;
if (ANI_OK != env->Class_GetStaticField_Float(cls, floatField, &floatValue)) {
std::cerr << "Set StaticField Fail " << className << "'" << std::endl;
}
- OH_LOG_ERROR(LOG_APP, "testTag Class_GetStaticField_Boolean result: %{public}f", floatValue);
- return;
-}
\ No newline at end of file
+ return true;
+}
diff --git a/code/ArkTS1.2/ANISample/entry/src/main/cpp/ani_array.cpp b/code/ArkTS1.2/ANISample/entry/src/main/cpp/ani_array.cpp
index ebd2e63d52917a91170d97630db2d721b359a68b..b426441f097155d54a550dfa3fbf54e2832ce5fc 100644
--- a/code/ArkTS1.2/ANISample/entry/src/main/cpp/ani_array.cpp
+++ b/code/ArkTS1.2/ANISample/entry/src/main/cpp/ani_array.cpp
@@ -24,98 +24,66 @@
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "ani/ani.h"
-#include "hilog/log.h"
#include
-
-#undef LOG_DOMAIN
-#undef LOG_TAG
-#define LOG_DOMAIN 0x3200 // 全局domain宏,标识业务领域
-#define LOG_TAG "MY_TAG" // 全局tag宏,标识模块日志tag
// Array Operations
-static void ProcessArray(ani_env *env, ani_object object, ani_array_double doubleArray)
+static ani_boolean ProcessArray(ani_env *env, ani_object object, ani_array_double doubleArray)
{
ani_size length;
if (ANI_OK != env->Array_GetLength(doubleArray, &length)) {
std::cerr << "Array_GetLength FAILED" << std::endl;
- return;
+ return false;
}
- OH_LOG_ERROR(LOG_APP, "testTag Array_GetLength result: %{public}d", length);
ani_array_double doubleValue;
if (ANI_OK != env->Array_New_Double(length, &doubleValue)) {
std::cerr << "Array_New_Double FAILED" << std::endl;
- return;
- }
- for (ani_int i = 0; i < length; ++i) {
- OH_LOG_ERROR(LOG_APP, "testTag Array_New_Double result: %{public}f", doubleValue[i]);
+ return false;
}
-
ani_array_int intValue;
if (ANI_OK != env->Array_New_Int(length, &intValue)) {
std::cerr << "Array_New_Int FAILED" << std::endl;
- return;
- }
- for (ani_int i = 0; i < length; ++i) {
- OH_LOG_ERROR(LOG_APP, "testTag Array_New_Int result: %{public}d", intValue[i]);
+ return false;
}
-
ani_array_short shortValue;
if (ANI_OK != env->Array_New_Short(length, &shortValue)) {
std::cerr << "Array_New_Short FAILED" << std::endl;
- return;
+ return false;
}
- for (ani_int i = 0; i < length; ++i) {
- OH_LOG_ERROR(LOG_APP, "testTag Array_New_Short result: %{public}d", shortValue[i]);
- }
-
ani_array_char charValue;
if (ANI_OK != env->Array_New_Char(length, &charValue)) {
std::cerr << "Array_New_Char FAILED" << std::endl;
- return;
+ return false;
}
std::cout << "Array int Content:" << doubleArray << std::endl;
+ return true;
}
-static void ProcessArray2(ani_env *env, ani_object object, ani_array_double doubleArray)
+static ani_boolean ProcessArray2(ani_env *env, ani_object object, ani_array_double doubleArray)
{
ani_size length;
if (ANI_OK != env->Array_GetLength(doubleArray, &length)) {
std::cerr << "Array_GetLength FAILED" << std::endl;
- return;
+ return false;
}
ani_array_char charValue;
if (ANI_OK != env->Array_New_Char(length, &charValue)) {
std::cerr << "Array_New_Char FAILED" << std::endl;
- return;
- }
- for (ani_int i = 0; i < length; ++i) {
- OH_LOG_ERROR(LOG_APP, "testTag Array_New_Char result: %{public}c", charValue[i]);
+ return false;
}
-
ani_array_boolean boolValue;
if (ANI_OK != env->Array_New_Boolean(length, &boolValue)) {
std::cerr << "Array_New_Boolean FAILED" << std::endl;
- return;
+ return false;
}
- for (ani_int i = 0; i < length; ++i) {
- OH_LOG_ERROR(LOG_APP, "testTag Array_New_Boolean result: %{public}d", boolValue[i]);
- }
-
ani_array_long longValue;
if (ANI_OK != env->Array_New_Long(length, &longValue)) {
std::cerr << "Array_New_Long FAILED" << std::endl;
- return;
- }
- for (ani_int i = 0; i < length; ++i) {
- OH_LOG_ERROR(LOG_APP, "testTag Array_New_Long result: %{public}ld", longValue[i]);
+ return false;
}
-
ani_array_float floatValue;
if (ANI_OK != env->Array_New_Float(length, &floatValue)) {
std::cerr << "Array_New_Float FAILED" << std::endl;
- return;
- }
- for (ani_int i = 0; i < length; ++i) {
- OH_LOG_ERROR(LOG_APP, "testTag Array_New_Float result: %{public}f", floatValue[i]);
+ return false;
}
std::cout << "Array int Content:" << doubleArray << std::endl;
+ return true;
}
\ No newline at end of file
diff --git a/code/ArkTS1.2/ANISample/entry/src/main/cpp/ani_calling_methods.cpp b/code/ArkTS1.2/ANISample/entry/src/main/cpp/ani_calling_methods.cpp
index bdbff7eec3a405acfd3fd7890f53891e5dc27733..eafa0b0028dc3a982d4f1d779d315d3cfb767a2d 100644
--- a/code/ArkTS1.2/ANISample/entry/src/main/cpp/ani_calling_methods.cpp
+++ b/code/ArkTS1.2/ANISample/entry/src/main/cpp/ani_calling_methods.cpp
@@ -26,310 +26,289 @@
#include "ani/ani.h"
#include
+
// Calling Instance Methods
-static void NativeVoidFunc(ani_env *env, ani_object obj)
+static void NativeByNameFunc(ani_env *env, ani_object obj)
{
- static const char *className = "Lentry/src/main/ets/entryability/EntryAbility/Calc;";
- ani_class cls;
- if (ANI_OK != env->FindClass(className, &cls)) {
- std::cerr << "Not found '" << className << "'" << std::endl;
- return;
- }
- ani_method managedMethod;
- if (ANI_OK != env->Class_FindMethod(cls, "ManagedVoidFunc", ":V", &managedMethod)) {
- std::cerr << "Class_FindMethod Fail" << std::endl;
- return;
- }
std::cout << "Print in Native Func" << std::endl;
- if (ANI_OK != env->Object_CallMethod_Void(obj, managedMethod)) {
- std::cerr << "Object_CallMethod_Void Fail" << std::endl;
+ if (ANI_OK != env->Object_CallMethodByName_Void(obj, "ManagedByNameVoidFunc", ":V")) {
+ std::cerr << "Object_CallMethodByName_Void Fail" << std::endl;
return;
}
}
-static ani_boolean NativeBoolFunc(ani_env *env, ani_object obj)
+static ani_double NativeByNameDoubleFunc([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object obj)
{
- static const char *className = "Lentry/src/main/ets/entryability/EntryAbility/Calc;";
- ani_class cls;
- if (ANI_OK != env->FindClass(className, &cls)) {
- std::cerr << "Not found '" << className << "'" << std::endl;
- return false;
- }
- ani_method managedMethod;
- if (ANI_OK != env->Class_FindMethod(cls, "ManagedBoolFunc", ":Z", &managedMethod)) {
- std::cerr << "Class_FindMethod Fail" << std::endl;
- return false;
+ ani_double doubleValue;
+ if (ANI_OK != env->Object_CallMethodByName_Double(obj, "ManagedByNameDoubleFunc", ":D", &doubleValue)) {
+ std::cerr << "Object_CallMethodByName_Double Fail" << std::endl;
+ return 0.0;
}
- std::cout << "Print in Native Func" << std::endl;
+ return doubleValue;
+}
+
+static ani_boolean NativeByNameBoolFunc([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object obj)
+{
ani_boolean boolValue;
- if (ANI_OK != env->Object_CallMethod_Boolean(obj, managedMethod, &boolValue)) {
- std::cerr << "Object_CallMethod_Boolean Fail" << std::endl;
+ if (ANI_OK != env->Object_CallMethodByName_Boolean(obj, "ManagedByNameBoolFunc", ":Z", &boolValue)) {
+ std::cerr << "Object_CallMethodByName_Double Fail" << std::endl;
return false;
}
return boolValue;
}
-static ani_int NativeIntFunc([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object obj)
+static ani_int NativeByNameIntFunc([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object obj)
{
- static const char *className = "Lentry/src/main/ets/entryability/EntryAbility/Calc;";
- ani_class cls;
- if (ANI_OK != env->FindClass(className, &cls)) {
- std::cerr << "Not found '" << className << "'" << std::endl;
- return 0;
- }
- ani_method managedMethod;
- if (ANI_OK != env->Class_FindMethod(cls, "ManagedIntFunc", ":I", &managedMethod)) {
- std::cerr << "Class_FindMethod Fail" << std::endl;
- return 0;
- }
- std::cout << "Print in Native Func" << std::endl;
ani_int intValue;
- if (ANI_OK != env->Object_CallMethod_Int(obj, managedMethod, &intValue)) {
- std::cerr << "Object_CallMethod_Int Fail" << std::endl;
- return 0;
+ if (ANI_OK != env->Object_CallMethodByName_Int(obj, "ManagedByNameIntFunc", ":I", &intValue)) {
+ std::cerr << "Object_CallMethodByName_Int Fail" << std::endl;
+ return false;
}
return intValue;
}
-
-static ani_short NativeShortFunc([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object obj)
+static ani_short NativeByNameShortFunc([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object obj)
{
- static const char *className = "Lentry/src/main/ets/entryability/EntryAbility/Calc;";
- ani_class cls;
- if (ANI_OK != env->FindClass(className, &cls)) {
- std::cerr << "Not found '" << className << "'" << std::endl;
+ ani_short shortValue;
+ if (ANI_OK != env->Object_CallMethodByName_Short(obj, "ManagedByNameShortFunc", ":S", &shortValue)) {
+ std::cerr << "Object_CallMethodByName_Short Fail" << std::endl;
return 0;
}
- ani_method managedMethod;
- if (ANI_OK != env->Class_FindMethod(cls, "ManagedShortFunc", ":S", &managedMethod)) {
- std::cerr << "Class_FindMethod Fail" << std::endl;
+ return shortValue;
+}
+
+static ani_long NativeByNameLongFunc([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object obj)
+{
+ ani_long longValue;
+ if (ANI_OK != env->Object_CallMethodByName_Long(obj, "ManagedByNameLongFunc", ":J", &longValue)) {
+ std::cerr << "Object_CallMethodByName_Long Fail" << std::endl;
return 0;
}
- std::cout << "Print in Native Func" << std::endl;
- ani_short shortValue;
- if (ANI_OK != env->Object_CallMethod_Short(obj, managedMethod, &shortValue)) {
- std::cerr << "Object_CallMethod_Short Fail" << std::endl;
- return 0;
+ return longValue;
+}
+
+static ani_char NativeByNameCharFunc([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object obj)
+{
+ ani_char charValue;
+ if (ANI_OK != env->Object_CallMethodByName_Char(obj, "ManagedByNameCharFunc", ":C", &charValue)) {
+ std::cerr << "Object_CallMethodByName_Char Fail" << std::endl;
+ return '0';
}
- return shortValue;
+ return charValue;
+}
+
+static ani_float NativeByNameFloatFunc([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object obj)
+{
+ ani_float floatValue;
+ if (ANI_OK != env->Object_CallMethodByName_Float(obj, "ManagedByNameFloatFunc", ":F", &floatValue)) {
+ std::cerr << "Object_CallMethodByName_Float Fail" << std::endl;
+ return 0.0;
+ }
+ return floatValue;
}
-static ani_long NativeLongFunc([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object obj)
+static ani_byte NativeByNameByteFunc([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object obj)
+{
+ ani_byte byteValue;
+ if (ANI_OK != env->Object_CallMethodByName_Byte(obj, "ManagedByNameByteFunc", ":B", &byteValue)) {
+ std::cerr << "Object_CallMethodByName_Byte Fail" << std::endl;
+ return 0x0;
+ }
+ return byteValue;
+}
+// todo Calling Static Methods
+static void NativeStaticFunc(ani_env *env, ani_object obj)
{
- static const char *className = "Lentry/src/main/ets/entryability/EntryAbility/Calc;";
+ static const char *className = "Lentry/src/main/ets/pages/Index/Calc;";
ani_class cls;
if (ANI_OK != env->FindClass(className, &cls)) {
std::cerr << "Not found '" << className << "'" << std::endl;
- return 0;
+ return;
}
- ani_method managedMethod;
- if (ANI_OK != env->Class_FindMethod(cls, "ManagedLongFunc", ":J", &managedMethod)) {
- std::cerr << "Class_FindMethod Fail" << std::endl;
- return 0;
+ ani_static_method managedMethod;
+ if (ANI_OK != env->Class_FindStaticMethod(cls, "ManagedStaticFunc", ":V", &managedMethod)) {
+ std::cerr << "Class_FindStaticMethod Fail" << std::endl;
+ return;
}
- std::cout << "Print in Native Func" << std::endl;
- ani_long longValue;
- if (ANI_OK != env->Object_CallMethod_Long(obj, managedMethod, &longValue)) {
- std::cerr << "Object_CallMethod_Long Fail" << std::endl;
- return 0;
+ std::cout << "Print in ManagedStaticFunc " << std::endl;
+ if (ANI_OK != env->Class_CallStaticMethod_Void(cls, managedMethod, ":V")) {
+ std::cerr << "Class_CallStaticMethod_Void Fail" << std::endl;
+ return;
}
- return longValue;
}
-static ani_double NativeDoubleFunc([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object obj)
+static ani_double NativeStaticFuncDouble(ani_env *env, ani_object obj)
{
- static const char *className = "Lentry/src/main/ets/entryability/EntryAbility/Calc;";
+ static const char *className = "Lentry/src/main/ets/pages/Index/Calc;";
ani_class cls;
if (ANI_OK != env->FindClass(className, &cls)) {
std::cerr << "Not found '" << className << "'" << std::endl;
- return 0;
+ return 0.0;
}
- ani_method managedMethod;
- if (ANI_OK != env->Class_FindMethod(cls, "ManagedDoubleFunc", ":D", &managedMethod)) {
- std::cerr << "Class_FindMethod Fail" << std::endl;
- return 0;
+ ani_static_method managedMethod;
+ if (ANI_OK != env->Class_FindStaticMethod(cls, "ManagedStaticFuncDouble", ":D", &managedMethod)) {
+ std::cerr << "Class_FindStaticMethod Fail" << std::endl;
+ return 0.0;
}
- std::cout << "Print in Native Func" << std::endl;
ani_double doubleValue;
- if (ANI_OK != env->Object_CallMethod_Double(obj, managedMethod, &doubleValue)) {
- std::cerr << "Object_CallMethod_Double Fail" << std::endl;
- return 0;
+ std::cout << "Print in ManagedStaticFuncDouble " << std::endl;
+ if (ANI_OK != env->Class_CallStaticMethod_Double(cls, managedMethod, &doubleValue)) {
+ std::cerr << "Class_CallStaticMethod_Double Fail" << std::endl;
+ return 0.0;
}
return doubleValue;
}
-static ani_float NativeFloatFunc([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object obj)
+static ani_float NativeStaticFuncFloat(ani_env *env, ani_object obj)
{
- static const char *className = "Lentry/src/main/ets/entryability/EntryAbility/Calc;";
+ static const char *className = "Lentry/src/main/ets/pages/Index/Calc;";
ani_class cls;
if (ANI_OK != env->FindClass(className, &cls)) {
std::cerr << "Not found '" << className << "'" << std::endl;
return 0.0;
}
- ani_method managedMethod;
- if (ANI_OK != env->Class_FindMethod(cls, "ManagedFloatFunc", ":F", &managedMethod)) {
- std::cerr << "Class_FindMethod Fail" << std::endl;
+ ani_static_method managedMethod;
+ if (ANI_OK != env->Class_FindStaticMethod(cls, "ManagedStaticFuncFloat", ":F", &managedMethod)) {
+ std::cerr << "Class_FindStaticMethod Fail" << std::endl;
return 0.0;
}
- std::cout << "Print in Native Func" << std::endl;
ani_float floatValue;
- if (ANI_OK != env->Object_CallMethod_Float(obj, managedMethod, &floatValue)) {
- std::cerr << "Object_CallMethod_Float Fail" << std::endl;
+ std::cout << "Print in ManagedStaticFuncFloat " << std::endl;
+ if (ANI_OK != env->Class_CallStaticMethod_Float(cls, managedMethod, &floatValue)) {
+ std::cerr << "Class_CallStaticMethod_Float Fail" << std::endl;
return 0.0;
}
return floatValue;
}
-static ani_char NativeCharFunc([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object obj)
+static ani_char NativeStaticFuncChar(ani_env *env, ani_object obj)
{
- static const char *className = "Lentry/src/main/ets/entryability/EntryAbility/Calc;";
+ static const char *className = "Lentry/src/main/ets/pages/Index/Calc;";
ani_class cls;
if (ANI_OK != env->FindClass(className, &cls)) {
std::cerr << "Not found '" << className << "'" << std::endl;
- return 0;
+ return ' ';
}
- ani_method managedMethod;
- if (ANI_OK != env->Class_FindMethod(cls, "ManagedCharFunc", ":C", &managedMethod)) {
- std::cerr << "Class_FindMethod Fail" << std::endl;
- return 0;
+ ani_static_method managedMethod;
+ if (ANI_OK != env->Class_FindStaticMethod(cls, "ManagedStaticFuncChar", ":C", &managedMethod)) {
+ std::cerr << "Class_FindStaticMethod Fail" << std::endl;
+ return ' ';
}
- std::cout << "Print in Native Func" << std::endl;
ani_char charValue;
- if (ANI_OK != env->Object_CallMethod_Char(obj, managedMethod, &charValue)) {
- std::cerr << "Object_CallMethod_Char Fail" << std::endl;
- return 0;
+ std::cout << "Print in ManagedStaticFuncChar " << std::endl;
+ if (ANI_OK != env->Class_CallStaticMethod_Char(cls, managedMethod, &charValue)) {
+ std::cerr << "Class_CallStaticMethod_Char Fail" << std::endl;
+ return ' ';
}
return charValue;
}
-static ani_byte NativeByteFunc([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object obj)
+static ani_byte NativeStaticFuncByte(ani_env *env, ani_object obj)
{
- static const char *className = "Lentry/src/main/ets/entryability/EntryAbility/Calc;";
+ static const char *className = "Lentry/src/main/ets/pages/Index/Calc;";
ani_class cls;
if (ANI_OK != env->FindClass(className, &cls)) {
std::cerr << "Not found '" << className << "'" << std::endl;
- return 0;
+ return 0x0;
}
- ani_method managedMethod;
- if (ANI_OK != env->Class_FindMethod(cls, "ManagedByteFunc", ":B", &managedMethod)) {
- std::cerr << "Class_FindMethod Fail" << std::endl;
- return 0;
+ ani_static_method managedMethod;
+ if (ANI_OK != env->Class_FindStaticMethod(cls, "ManagedStaticFuncByte", ":B", &managedMethod)) {
+ std::cerr << "Class_FindStaticMethod Fail" << std::endl;
+ return 0x0;
}
- std::cout << "Print in Native Func" << std::endl;
ani_byte byteValue;
- if (ANI_OK != env->Object_CallMethod_Byte(obj, managedMethod, &byteValue)) {
- std::cerr << "Object_CallMethod_Byte Fail" << std::endl;
- return 0;
+ std::cout << "Print in ManagedStaticFuncByte " << std::endl;
+ if (ANI_OK != env->Class_CallStaticMethod_Byte(cls, managedMethod, &byteValue)) {
+ std::cerr << "Class_CallStaticMethod_Byte Fail" << std::endl;
+ return 0x0;
}
return byteValue;
}
-static void NativeByNameFunc(ani_env *env, ani_object obj)
+static ani_boolean NativeStaticFuncBoolean(ani_env *env, ani_object obj)
{
- std::cout << "Print in Native Func" << std::endl;
- if (ANI_OK != env->Object_CallMethodByName_Void(obj, "ManagedByNameVoidFunc", ":V")) {
- std::cerr << "Object_CallMethodByName_Void Fail" << std::endl;
- return;
+ static const char *className = "Lentry/src/main/ets/pages/Index/Calc;";
+ ani_class cls;
+ if (ANI_OK != env->FindClass(className, &cls)) {
+ std::cerr << "Not found '" << className << "'" << std::endl;
+ return false;
}
-}
-
-static ani_double NativeByNameDoubleFunc([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object obj)
-{
- ani_double doubleValue;
- if (ANI_OK != env->Object_CallMethodByName_Double(obj, "ManagedByNameDoubleFunc", ":D", &doubleValue)) {
- std::cerr << "Object_CallMethodByName_Double Fail" << std::endl;
- return 0.0;
+ ani_static_method managedMethod;
+ if (ANI_OK != env->Class_FindStaticMethod(cls, "ManagedStaticFuncBoolean", ":Z", &managedMethod)) {
+ std::cerr << "Class_FindStaticMethod Fail" << std::endl;
+ return false;
}
- return doubleValue;
-}
-
-static ani_boolean NativeByNameBoolFunc([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object obj)
-{
ani_boolean boolValue;
- if (ANI_OK != env->Object_CallMethodByName_Boolean(obj, "ManagedByNameBoolFunc", ":Z", &boolValue)) {
- std::cerr << "Object_CallMethodByName_Double Fail" << std::endl;
+ std::cout << "Print in ManagedStaticFuncBoolean " << std::endl;
+ if (ANI_OK != env->Class_CallStaticMethod_Boolean(cls, managedMethod, &boolValue)) {
+ std::cerr << "Class_CallStaticMethod_Boolean Fail" << std::endl;
return false;
}
return boolValue;
}
-static ani_int NativeByNameIntFunc([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object obj)
+static ani_int NativeStaticFuncInt(ani_env *env, ani_object obj)
{
- ani_int intValue;
- if (ANI_OK != env->Object_CallMethodByName_Int(obj, "ManagedByNameIntFunc", ":I", &intValue)) {
- std::cerr << "Object_CallMethodByName_Int Fail" << std::endl;
- return false;
+ static const char *className = "Lentry/src/main/ets/pages/Index/Calc;";
+ ani_class cls;
+ if (ANI_OK != env->FindClass(className, &cls)) {
+ std::cerr << "Not found '" << className << "'" << std::endl;
+ return 0;
}
- return intValue;
-}
-
-static ani_short NativeByNameShortFunc([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object obj)
-{
- ani_short shortValue;
- if (ANI_OK != env->Object_CallMethodByName_Short(obj, "ManagedByNameShortFunc", ":S", &shortValue)) {
- std::cerr << "Object_CallMethodByName_Short Fail" << std::endl;
+ ani_static_method managedMethod;
+ if (ANI_OK != env->Class_FindStaticMethod(cls, "ManagedStaticFuncInt", ":I", &managedMethod)) {
+ std::cerr << "Class_FindStaticMethod Fail" << std::endl;
return 0;
}
- return shortValue;
-}
-
-static ani_long NativeByNameLongFunc([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object obj)
-{
- ani_long longValue;
- if (ANI_OK != env->Object_CallMethodByName_Long(obj, "ManagedByNameLongFunc", ":J", &longValue)) {
- std::cerr << "Object_CallMethodByName_Long Fail" << std::endl;
+ ani_int intValue;
+ std::cout << "Print in ManagedStaticFuncInt " << std::endl;
+ if (ANI_OK != env->Class_CallStaticMethod_Int(cls, managedMethod, &intValue)) {
+ std::cerr << "Class_CallStaticMethod_Double Fail" << std::endl;
return 0;
}
- return longValue;
+ return intValue;
}
-static ani_char NativeByNameCharFunc([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object obj)
+static ani_short NativeStaticFuncShort(ani_env *env, ani_object obj)
{
- ani_char charValue;
- if (ANI_OK != env->Object_CallMethodByName_Char(obj, "ManagedByNameCharFunc", ":C", &charValue)) {
- std::cerr << "Object_CallMethodByName_Char Fail" << std::endl;
- return '0';
+ static const char *className = "Lentry/src/main/ets/pages/Index/Calc;";
+ ani_class cls;
+ if (ANI_OK != env->FindClass(className, &cls)) {
+ std::cerr << "Not found '" << className << "'" << std::endl;
+ return 0;
}
- return charValue;
-}
-
-static ani_float NativeByNameFloatFunc([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object obj)
-{
- ani_float floatValue;
- if (ANI_OK != env->Object_CallMethodByName_Float(obj, "ManagedByNameFloatFunc", ":F", &floatValue)) {
- std::cerr << "Object_CallMethodByName_Float Fail" << std::endl;
- return 0.0;
+ ani_static_method managedMethod;
+ if (ANI_OK != env->Class_FindStaticMethod(cls, "ManagedStaticFuncShort", ":S", &managedMethod)) {
+ std::cerr << "Class_FindStaticMethod Fail" << std::endl;
+ return 0;
}
- return floatValue;
-}
-
-static ani_byte NativeByNameByteFunc([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object obj)
-{
- ani_byte byteValue;
- if (ANI_OK != env->Object_CallMethodByName_Byte(obj, "ManagedByNameByteFunc", ":B", &byteValue)) {
- std::cerr << "Object_CallMethodByName_Byte Fail" << std::endl;
- return 0x0;
+ ani_short shortValue;
+ std::cout << "Print in ManagedStaticFuncShort " << std::endl;
+ if (ANI_OK != env->Class_CallStaticMethod_Short(cls, managedMethod, &shortValue)) {
+ std::cerr << "Class_CallStaticMethod_Short Fail" << std::endl;
+ return 0;
}
- return byteValue;
+ return shortValue;
}
-// todo Calling Static Methods
-static void NativeStaticFunc(ani_env *env, ani_object obj)
+static ani_long NativeStaticFuncLong(ani_env *env, ani_object obj)
{
- static const char *className = "Lentry/src/main/ets/entryability/EntryAbility/Calc;";
+ static const char *className = "Lentry/src/main/ets/pages/Index/Calc;";
ani_class cls;
if (ANI_OK != env->FindClass(className, &cls)) {
std::cerr << "Not found '" << className << "'" << std::endl;
- return;
+ return 0;
}
ani_static_method managedMethod;
- if (ANI_OK != env->Class_FindStaticMethod(cls, "ManagedStaticFunc", ":V", &managedMethod)) {
+ if (ANI_OK != env->Class_FindStaticMethod(cls, "ManagedStaticFuncLong", ":J", &managedMethod)) {
std::cerr << "Class_FindStaticMethod Fail" << std::endl;
- return;
+ return 0;
}
- std::cout << "Print in ManagedStaticFunc " << std::endl;
- if (ANI_OK != env->Class_CallStaticMethod_Void(cls, managedMethod, ":V")) {
- std::cerr << "Class_CallStaticMethod_Void Fail" << std::endl;
- return;
+ ani_long longValue;
+ std::cout << "Print in ManagedStaticFuncLong " << std::endl;
+ if (ANI_OK != env->Class_CallStaticMethod_Long(cls, managedMethod, &longValue)) {
+ std::cerr << "Class_CallStaticMethod_Long Fail" << std::endl;
+ return 0;
}
+ return longValue;
}
\ No newline at end of file
diff --git a/code/ArkTS1.2/ANISample/entry/src/main/cpp/ani_class_operation.cpp b/code/ArkTS1.2/ANISample/entry/src/main/cpp/ani_class_operation.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..c1de30c6c5e800605e3f59a0dcb41a9f9d2d5b23
--- /dev/null
+++ b/code/ArkTS1.2/ANISample/entry/src/main/cpp/ani_class_operation.cpp
@@ -0,0 +1,223 @@
+/**
+ *
+ * Copyright (c) 2025 Huawei Device Co., Ltd.
+ *
+ * All rights reserved.
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice,this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * THIS IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS,
+ *
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "ani/ani.h"
+#include
+
+static void NativeVoidFunc(ani_env *env, ani_object obj)
+{
+ static const char *className = "Lentry/src/main/ets/pages/Index/Calc;";
+ ani_class cls;
+ if (ANI_OK != env->FindClass(className, &cls)) {
+ std::cerr << "Not found '" << className << "'" << std::endl;
+ return;
+ }
+ ani_method managedMethod;
+ if (ANI_OK != env->Class_FindMethod(cls, "ManagedVoidFunc", ":V", &managedMethod)) {
+ std::cerr << "Class_FindMethod Fail" << std::endl;
+ return;
+ }
+ std::cout << "Print in Native Func" << std::endl;
+ if (ANI_OK != env->Object_CallMethod_Void(obj, managedMethod)) {
+ std::cerr << "Object_CallMethod_Void Fail" << std::endl;
+ return;
+ }
+}
+
+static ani_boolean NativeBoolFunc(ani_env *env, ani_object obj)
+{
+ static const char *className = "Lentry/src/main/ets/pages/Index/Calc;";
+ ani_class cls;
+ if (ANI_OK != env->FindClass(className, &cls)) {
+ std::cerr << "Not found '" << className << "'" << std::endl;
+ return false;
+ }
+ ani_method managedMethod;
+ if (ANI_OK != env->Class_FindMethod(cls, "ManagedBoolFunc", ":Z", &managedMethod)) {
+ std::cerr << "Class_FindMethod Fail" << std::endl;
+ return false;
+ }
+ std::cout << "Print in Native Func" << std::endl;
+ ani_boolean boolValue;
+ if (ANI_OK != env->Object_CallMethod_Boolean(obj, managedMethod, &boolValue)) {
+ std::cerr << "Object_CallMethod_Boolean Fail" << std::endl;
+ return false;
+ }
+ return boolValue;
+}
+
+static ani_int NativeIntFunc([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object obj)
+{
+ static const char *className = "Lentry/src/main/ets/pages/Index/Calc;";
+ ani_class cls;
+ if (ANI_OK != env->FindClass(className, &cls)) {
+ std::cerr << "Not found '" << className << "'" << std::endl;
+ return 0;
+ }
+ ani_method managedMethod;
+ if (ANI_OK != env->Class_FindMethod(cls, "ManagedIntFunc", ":I", &managedMethod)) {
+ std::cerr << "Class_FindMethod Fail" << std::endl;
+ return 0;
+ }
+ std::cout << "Print in Native Func" << std::endl;
+ ani_int intValue;
+ if (ANI_OK != env->Object_CallMethod_Int(obj, managedMethod, &intValue)) {
+ std::cerr << "Object_CallMethod_Int Fail" << std::endl;
+ return 0;
+ }
+ return intValue;
+}
+
+static ani_short NativeShortFunc([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object obj)
+{
+ static const char *className = "Lentry/src/main/ets/pages/Index/Calc;";
+ ani_class cls;
+ if (ANI_OK != env->FindClass(className, &cls)) {
+ std::cerr << "Not found '" << className << "'" << std::endl;
+ return 0;
+ }
+ ani_method managedMethod;
+ if (ANI_OK != env->Class_FindMethod(cls, "ManagedShortFunc", ":S", &managedMethod)) {
+ std::cerr << "Class_FindMethod Fail" << std::endl;
+ return 0;
+ }
+ std::cout << "Print in Native Func" << std::endl;
+ ani_short shortValue;
+ if (ANI_OK != env->Object_CallMethod_Short(obj, managedMethod, &shortValue)) {
+ std::cerr << "Object_CallMethod_Short Fail" << std::endl;
+ return 0;
+ }
+ return shortValue;
+}
+
+static ani_long NativeLongFunc([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object obj)
+{
+ static const char *className = "Lentry/src/main/ets/pages/Index/Calc;";
+ ani_class cls;
+ if (ANI_OK != env->FindClass(className, &cls)) {
+ std::cerr << "Not found '" << className << "'" << std::endl;
+ return 0;
+ }
+ ani_method managedMethod;
+ if (ANI_OK != env->Class_FindMethod(cls, "ManagedLongFunc", ":J", &managedMethod)) {
+ std::cerr << "Class_FindMethod Fail" << std::endl;
+ return 0;
+ }
+ std::cout << "Print in Native Func" << std::endl;
+ ani_long longValue;
+ if (ANI_OK != env->Object_CallMethod_Long(obj, managedMethod, &longValue)) {
+ std::cerr << "Object_CallMethod_Long Fail" << std::endl;
+ return 0;
+ }
+ return longValue;
+}
+
+static ani_double NativeDoubleFunc([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object obj)
+{
+ static const char *className = "Lentry/src/main/ets/pages/Index/Calc;";
+ ani_class cls;
+ if (ANI_OK != env->FindClass(className, &cls)) {
+ std::cerr << "Not found '" << className << "'" << std::endl;
+ return 0;
+ }
+ ani_method managedMethod;
+ if (ANI_OK != env->Class_FindMethod(cls, "ManagedDoubleFunc", ":D", &managedMethod)) {
+ std::cerr << "Class_FindMethod Fail" << std::endl;
+ return 0;
+ }
+ std::cout << "Print in Native Func" << std::endl;
+ ani_double doubleValue;
+ if (ANI_OK != env->Object_CallMethod_Double(obj, managedMethod, &doubleValue)) {
+ std::cerr << "Object_CallMethod_Double Fail" << std::endl;
+ return 0;
+ }
+ return doubleValue;
+}
+
+static ani_float NativeFloatFunc([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object obj)
+{
+ static const char *className = "Lentry/src/main/ets/pages/Index/Calc;";
+ ani_class cls;
+ if (ANI_OK != env->FindClass(className, &cls)) {
+ std::cerr << "Not found '" << className << "'" << std::endl;
+ return 0.0;
+ }
+ ani_method managedMethod;
+ if (ANI_OK != env->Class_FindMethod(cls, "ManagedFloatFunc", ":F", &managedMethod)) {
+ std::cerr << "Class_FindMethod Fail" << std::endl;
+ return 0.0;
+ }
+ std::cout << "Print in Native Func" << std::endl;
+ ani_float floatValue;
+ if (ANI_OK != env->Object_CallMethod_Float(obj, managedMethod, &floatValue)) {
+ std::cerr << "Object_CallMethod_Float Fail" << std::endl;
+ return 0.0;
+ }
+ return floatValue;
+}
+
+static ani_char NativeCharFunc([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object obj)
+{
+ static const char *className = "Lentry/src/main/ets/pages/Index/Calc;";
+ ani_class cls;
+ if (ANI_OK != env->FindClass(className, &cls)) {
+ std::cerr << "Not found '" << className << "'" << std::endl;
+ return 0;
+ }
+ ani_method managedMethod;
+ if (ANI_OK != env->Class_FindMethod(cls, "ManagedCharFunc", ":C", &managedMethod)) {
+ std::cerr << "Class_FindMethod Fail" << std::endl;
+ return 0;
+ }
+ std::cout << "Print in Native Func" << std::endl;
+ ani_char charValue;
+ if (ANI_OK != env->Object_CallMethod_Char(obj, managedMethod, &charValue)) {
+ std::cerr << "Object_CallMethod_Char Fail" << std::endl;
+ return 0;
+ }
+ return charValue;
+}
+
+static ani_byte NativeByteFunc([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object obj)
+{
+ static const char *className = "Lentry/src/main/ets/pages/Index/Calc;";
+ ani_class cls;
+ if (ANI_OK != env->FindClass(className, &cls)) {
+ std::cerr << "Not found '" << className << "'" << std::endl;
+ return 0;
+ }
+ ani_method managedMethod;
+ if (ANI_OK != env->Class_FindMethod(cls, "ManagedByteFunc", ":B", &managedMethod)) {
+ std::cerr << "Class_FindMethod Fail" << std::endl;
+ return 0;
+ }
+ std::cout << "Print in Native Func" << std::endl;
+ ani_byte byteValue;
+ if (ANI_OK != env->Object_CallMethod_Byte(obj, managedMethod, &byteValue)) {
+ std::cerr << "Object_CallMethod_Byte Fail" << std::endl;
+ return 0;
+ }
+ return byteValue;
+}
\ No newline at end of file
diff --git a/code/ArkTS1.2/ANISample/entry/src/main/cpp/ani_error.cpp b/code/ArkTS1.2/ANISample/entry/src/main/cpp/ani_error.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..3f0b7bd23e64e32e5fe371829a28bfd1fd4fed45
--- /dev/null
+++ b/code/ArkTS1.2/ANISample/entry/src/main/cpp/ani_error.cpp
@@ -0,0 +1,44 @@
+/**
+ *
+ * Copyright (c) 2025 Huawei Device Co., Ltd.
+ *
+ * All rights reserved.
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice,this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * THIS IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS,
+ *
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "ani/ani.h"
+#include
+ani_boolean ThrowError(ani_env *env, ani_object object, ani_object value)
+{
+ ani_class cls;
+ if (ANI_OK != env->FindClass("Lescompat/Error;", &cls)) {
+ std::cerr << "FindClass FAILED" << std::endl;
+ }
+ ani_type typeError = cls;
+ ani_boolean result;
+ if (ANI_OK != env->Object_InstanceOf(value, typeError, &result)) {
+ std::cerr << "Object_InstanceOf FAILED" << std::endl;
+ }
+ if (ANI_OK != env->ThrowError(static_cast(value))) {
+ std::cerr << "ThrowError FAILED" << std::endl;
+ }
+ return result;
+}
+
diff --git a/code/ArkTS1.2/ANISample/entry/src/main/cpp/ani_init.cpp b/code/ArkTS1.2/ANISample/entry/src/main/cpp/ani_init.cpp
index 529d5290c9ff94009f30c382c46ed1810da7296a..f6ff447184ddc4a2454eab7d8926683699b595e7 100644
--- a/code/ArkTS1.2/ANISample/entry/src/main/cpp/ani_init.cpp
+++ b/code/ArkTS1.2/ANISample/entry/src/main/cpp/ani_init.cpp
@@ -27,52 +27,61 @@
#include "ani_accessing_fields.cpp"
#include "ani_array.cpp"
#include "ani_calling_methods.cpp"
+#include "ani_error.cpp"
#include "ani_object.cpp"
#include "ani_references.cpp"
#include "ani_string.cpp"
#include "ani_versionInfo.cpp"
+#include "ani_vminterface.cpp"
+#include "ani_promise.cpp"
+#include "ani_class_operation.cpp"
+#include "ani_reflection.cpp"
#include
#include
#include
-#include "hilog/log.h"
-
-#undef LOG_DOMAIN
-#undef LOG_TAG
-#define LOG_DOMAIN 0x3200 // 全局domain宏,标识业务领域
-#define LOG_TAG "MY_TAG" // 全局tag宏,标识模块日志tag
-
auto Methods()
{
std::array method = {
+ ani_native_function{"GetVersionInfo", ":I", reinterpret_cast(GetVersionInfo)},
+ ani_native_function{"Global_Local_References", ":Z", reinterpret_cast(Global_Local_References)},
+ ani_native_function{"Weak_Global_References", ":Z", reinterpret_cast(Weak_Global_References)},
+ ani_native_function{"ProcessArray", "[D:Z", reinterpret_cast(ProcessArray)},
+ ani_native_function{"ProcessArray2", "[D:Z", reinterpret_cast(ProcessArray2)},
+ ani_native_function{"String_Operations", ":Lstd/core/String;", reinterpret_cast(String_Operations)},
ani_native_function{"UpdateFields", ":V", reinterpret_cast(UpdateFields)},
ani_native_function{"UpdateFields2", ":V", reinterpret_cast(UpdateFields2)},
- ani_native_function{"UpdateIntFields", ":I", reinterpret_cast(UpdateIntFields)},
- ani_native_function{"UpdateDoubleFields", ":D", reinterpret_cast(UpdateDoubleFields)},
- ani_native_function{"UpdateBoolFields", ":Z", reinterpret_cast(UpdateBoolFields)},
- ani_native_function{"UpdateShortFields", ":S", reinterpret_cast(UpdateShortFields)},
- ani_native_function{"UpdateLongFields", ":J", reinterpret_cast(UpdateLongFields)},
- ani_native_function{"UpdateCharFields", ":C", reinterpret_cast(UpdateCharFields)},
- ani_native_function{"UpdateFloatFields", ":F", reinterpret_cast(UpdateFloatFields)},
- ani_native_function{"UpdateByteFields", ":B", reinterpret_cast(UpdateByteFields)},
ani_native_function{"UpdateByNameFields", ":V", reinterpret_cast(UpdateByNameFields)},
ani_native_function{"UpdateByNameFields2", ":V", reinterpret_cast(UpdateByNameFields2)},
ani_native_function{"UpdateStaticFields", ":V", reinterpret_cast(UpdateStaticFields)},
ani_native_function{"UpdateStaticFields2", ":V", reinterpret_cast(UpdateStaticFields2)},
- ani_native_function{"ProcessArray", "[D:V", reinterpret_cast(ProcessArray)},
- ani_native_function{"ProcessArray2", "[D:V", reinterpret_cast(ProcessArray2)},
+ ani_native_function{"GetStaticFields", ":Z", reinterpret_cast(GetStaticFields)},
+ ani_native_function{"GetStaticFields2", ":Z", reinterpret_cast(GetStaticFields2)},
ani_native_function{"NativeVoidFunc", ":V", reinterpret_cast(NativeVoidFunc)},
ani_native_function{"NativeBoolFunc", ":Z", reinterpret_cast(NativeBoolFunc)},
ani_native_function{"NativeIntFunc", ":I", reinterpret_cast(NativeIntFunc)},
ani_native_function{"NativeLongFunc", ":J", reinterpret_cast(NativeLongFunc)},
+ ani_native_function{"NativeShortFunc", ":S", reinterpret_cast(NativeShortFunc)},
ani_native_function{"NativeDoubleFunc", ":D", reinterpret_cast(NativeDoubleFunc)},
ani_native_function{"NativeFloatFunc", ":F", reinterpret_cast(NativeFloatFunc)},
ani_native_function{"NativeCharFunc", ":C", reinterpret_cast(NativeCharFunc)},
ani_native_function{"NativeByteFunc", ":B", reinterpret_cast(NativeByteFunc)},
+
+ };
+ return method;
+}
+
+auto Methods2()
+{
+ std::array method = {
ani_native_function{"NativeStaticFunc", ":V", reinterpret_cast(NativeStaticFunc)},
- ani_native_function{"GetVersionInfo", ":I", reinterpret_cast(GetVersionInfo)},
- ani_native_function{"Global_Local_References", ":V", reinterpret_cast(Global_Local_References)},
- ani_native_function{"Weak_Global_References", ":V", reinterpret_cast(Weak_Global_References)},
- ani_native_function{"String_Operations", ":Lstd/core/String;", reinterpret_cast(String_Operations)},
+ ani_native_function{"NativeStaticFuncDouble", ":D", reinterpret_cast(NativeStaticFuncDouble)},
+ ani_native_function{"NativeStaticFuncFloat", ":F", reinterpret_cast(NativeStaticFuncFloat)},
+ ani_native_function{"NativeStaticFuncChar", ":C", reinterpret_cast(NativeStaticFuncChar)},
+ ani_native_function{"NativeStaticFuncByte", ":B", reinterpret_cast(NativeStaticFuncByte)},
+ ani_native_function{"NativeStaticFuncBoolean", ":Z", reinterpret_cast(NativeStaticFuncBoolean)},
+ ani_native_function{"NativeStaticFuncInt", ":I", reinterpret_cast(NativeStaticFuncInt)},
+ ani_native_function{"NativeStaticFuncShort", ":S", reinterpret_cast(NativeStaticFuncShort)},
+ ani_native_function{"NativeStaticFuncLong", ":J", reinterpret_cast(NativeStaticFuncLong)},
ani_native_function{"NativeByNameFunc", ":V", reinterpret_cast(NativeByNameFunc)},
ani_native_function{"NativeByNameDoubleFunc", ":D", reinterpret_cast(NativeByNameDoubleFunc)},
ani_native_function{"NativeByNameBoolFunc", ":Z", reinterpret_cast(NativeByNameBoolFunc)},
@@ -83,32 +92,47 @@ auto Methods()
ani_native_function{"NativeByNameFloatFunc", ":F", reinterpret_cast(NativeByNameFloatFunc)},
ani_native_function{"NativeByNameByteFunc", ":B", reinterpret_cast(NativeByNameByteFunc)},
ani_native_function{"HandleDoubleData", "D:D", reinterpret_cast(HandleDoubleData)},
+ ani_native_function{"ThrowError", "Lescompat/Error;:Z", reinterpret_cast(ThrowError)},
+ ani_native_function{"VMInterface", ":Z", reinterpret_cast(VMInterface)},
+ ani_native_function{"createPerson", ":Lentry/src/main/ets/pages/Index/Calc;",
+ reinterpret_cast(CreatePerson)},
+ ani_native_function{"thisIsPropertyGetter", ":I", reinterpret_cast(BindGet)},
+ ani_native_function{"thisIsPropertySetter", "I:V", reinterpret_cast(BindSet)},
+ ani_native_function{"execute", "Lentry/src/main/ets/pages/Index/Want;:I", reinterpret_cast(execute)},
+ ani_native_function{"gettid", ":I", reinterpret_cast(myGettid)},
+
};
return method;
}
-ANI_EXPORT ani_status ANI_Constructor(ani_vm *vm, uint32_t *result)
+static ani_status bindCase(ani_vm *vm, const char *clsName)
{
ani_env *env;
if (ANI_OK != vm->GetEnv(ANI_VERSION_1, &env)) {
std::cerr << "Unsupported ANI_VERSION_1" << std::endl;
return ANI_OUT_OF_REF;
}
- OH_LOG_ERROR(LOG_APP, "testTag get vm success start");
- if (ANI_OK != env->GetVM(&vm)) {
- std::cerr << "GetVM Fail" << std::endl;
- }
- OH_LOG_ERROR(LOG_APP, "testTag get vm success end");
- static const char *clsName = "Lentry/src/main/ets/entryability/EntryAbility/Calc;";
ani_class cls{};
if (ANI_OK != env->FindClass(clsName, &cls)) {
std::cerr << "Not found '" << clsName << "'" << std::endl;
return ANI_INVALID_ARGS;
}
- std::array method = Methods();
- if (ANI_OK != env->Class_BindNativeMethods(cls, method.data(), method.size())) {
+ std::array methodTmp = Methods();
+ std::array methodTmp2 = Methods2();
+ std::array methods;
+ std::copy(methodTmp.begin(), methodTmp.end(), methods.begin());
+ std::copy(methodTmp2.begin(), methodTmp2.end(), methods.begin() + methodTmp.size());
+ if (ANI_OK != env->Class_BindNativeMethods(cls, methods.data(), methods.size())) {
+ std::cerr << "Cannot bind native methods to '" << clsName << "'" << std::endl;
return ANI_INVALID_TYPE;
};
+ return ANI_OK;
+}
+
+ANI_EXPORT ani_status ANI_Constructor(ani_vm *vm, uint32_t *result)
+{
+ std::cout << "testTag : entering libentry.so's ANI_Constructor" << std::endl;
+ bindCase(vm, "Lentry/src/main/ets/pages/Index/Calc;");
*result = ANI_VERSION_1;
return ANI_OK;
}
\ No newline at end of file
diff --git a/code/ArkTS1.2/ANISample/entry/src/main/cpp/ani_object.cpp b/code/ArkTS1.2/ANISample/entry/src/main/cpp/ani_object.cpp
index 14624ffa900c231e887e29f6c8bf7e3ac8633d6d..cb0c1241058cc4005c7f0426145705e87ae8e356 100644
--- a/code/ArkTS1.2/ANISample/entry/src/main/cpp/ani_object.cpp
+++ b/code/ArkTS1.2/ANISample/entry/src/main/cpp/ani_object.cpp
@@ -24,14 +24,8 @@
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "ani/ani.h"
-#include "hilog/log.h"
#include
-#undef LOG_DOMAIN
-#undef LOG_TAG
-#define LOG_DOMAIN 0x3200 // 全局domain宏,标识业务领域
-#define LOG_TAG "MY_TAG" // 全局tag宏,标识模块日志tag
-
static ani_double HandleDoubleData([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_fn_object fnObj,
ani_double val_double1)
{
@@ -48,16 +42,13 @@ static ani_double HandleDoubleData([[maybe_unused]] ani_env *env, [[maybe_unused
if (ANI_OK != env->Object_New(cls, ctor, &rs, val_double1)) {
std::cerr << "Object_New fail " << std::endl;
}
- OH_LOG_ERROR(LOG_APP, "testTag Object_New success");
ani_type result;
if (ANI_OK != env->Object_GetType(rs, &result)) {
std::cerr << "Object_GetType fail " << std::endl;
}
- OH_LOG_ERROR(LOG_APP, "testTag Object_GetType success");
- ani_boolean boolresult;
- if (ANI_OK != env->Object_InstanceOf(fnObj, cls, &boolresult)) {
+ ani_boolean boolResult;
+ if (ANI_OK != env->Object_InstanceOf(fnObj, cls, &boolResult)) {
std::cerr << "Object_InstanceOf fail " << std::endl;
}
- OH_LOG_ERROR(LOG_APP, "testTag Object_InstanceOf result: %{public}d", boolresult);
return val_double1;
}
\ No newline at end of file
diff --git a/code/ArkTS1.2/ANISample/entry/src/main/cpp/ani_promise.cpp b/code/ArkTS1.2/ANISample/entry/src/main/cpp/ani_promise.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..4e5309b4d24613b4a23f6aa55697fa3523466160
--- /dev/null
+++ b/code/ArkTS1.2/ANISample/entry/src/main/cpp/ani_promise.cpp
@@ -0,0 +1,42 @@
+/**
+ *
+ * Copyright (c) 2025 Huawei Device Co., Ltd.
+ *
+ * All rights reserved.
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice,this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * THIS IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS,
+ *
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include
+#include
+#include
+
+#define NUM_5 5
+
+static int execute([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object obj, [[maybe_unused]] ani_object want)
+{
+ std::cout << "Print in execute in thread" << gettid() <
-#undef LOG_DOMAIN
-#undef LOG_TAG
-#define LOG_DOMAIN 0x3200 // 全局domain宏,标识业务领域
-#define LOG_TAG "MY_TAG" // 全局tag宏,标识模块日志tag
-//// Global and Local References
-static void Global_Local_References([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object object)
+static ani_boolean Global_Local_References([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object object)
{
ani_ref ref;
ani_ref result;
if (ANI_OK != env->GlobalReference_Create(ref, &result)) {
std::cerr << "GlobalReference_Create FAILED" << std::endl;
- return;
+ return false;
}
- OH_LOG_ERROR(LOG_APP, "testTag GlobalReference_Create success");
ani_boolean isNull;
if (ANI_OK != env->Reference_IsNull(result, &isNull)) {
std::cerr << "Reference_IsNull" << std::endl;
- return;
+ return false;
}
ani_ref ref0 = nullptr;
ani_ref ref1 = nullptr;
- ani_boolean boolresult;
- if (ANI_OK != env->Reference_StrictEquals(ref0, ref1, &boolresult)) {
+ ani_boolean boolResult;
+ if (ANI_OK != env->Reference_StrictEquals(ref0, ref1, &boolResult)) {
std::cerr << "Reference_StrictEquals" << std::endl;
- return;
+ return false;
}
if (ANI_OK != env->GlobalReference_Delete(result)) {
std::cerr << "Reference_IsNull" << std::endl;
- return;
+ return false;
}
- OH_LOG_ERROR(LOG_APP, "testTag GlobalReference_Delete success");
+ return true;
}
// Weak Global References;
-static void Weak_Global_References([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object object)
+static ani_boolean Weak_Global_References([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object object)
{
ani_ref ref;
ani_wref result;
if (ANI_OK != env->WeakReference_Create(ref, &result)) {
std::cerr << "WeakReference_Create FAILED" << std::endl;
- return;
+ return false;
}
- OH_LOG_ERROR(LOG_APP, "testTag WeakReference_Create success");
if (ANI_OK != env->WeakReference_Delete(result)) {
std::cerr << "WeakReference_Delete FAILED" << std::endl;
- return;
+ return false;
}
- OH_LOG_ERROR(LOG_APP, "testTag WeakReference_Delete success");
+ return true;
}
\ No newline at end of file
diff --git a/code/ArkTS1.2/ANISample/entry/src/main/cpp/ani_reflection.cpp b/code/ArkTS1.2/ANISample/entry/src/main/cpp/ani_reflection.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..27c8364a44f329bedc8f4398e97c2e9c8a9dcc81
--- /dev/null
+++ b/code/ArkTS1.2/ANISample/entry/src/main/cpp/ani_reflection.cpp
@@ -0,0 +1,91 @@
+/**
+ *
+ * Copyright (c) 2025 Huawei Device Co., Ltd.
+ *
+ * All rights reserved.
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice,this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * THIS IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS,
+ *
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include
+#include
+
+#define NUM_5000 5000
+
+void CreateInstance(ani_env *env, ani_class *cls, ani_object *person_obj)
+{
+ static const char *className = "Lentry/src/main/ets/pages/Index/Calc;";
+ if (ANI_OK != env->FindClass(className, cls)) {
+ std::cerr << "Not found '" << className << "'" << std::endl;
+ return;
+ }
+ ani_method ctor;
+ if (ANI_OK != env->Class_FindMethod(*cls, "", nullptr, &ctor)) {
+ std::cerr << "get ctor Failed'" << className << "'" << std::endl;
+ return;
+ }
+ if (ANI_OK != env->Object_New(*cls, ctor, person_obj)) {
+ std::cerr << "Create Object Failed'" << className << "'" << std::endl;
+ return;
+ }
+}
+
+static ani_object CreatePerson([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object object)
+{
+ static const char *className = "Lentry/src/main/ets/pages/Index/Calc;";
+ ani_object person_obj = {};
+ ani_class cls;
+ CreateInstance(env, &cls, &person_obj);
+ std::string name = "China";
+ ani_string name_string{};
+ if (ANI_OK != env->String_NewUTF8(name.c_str(), name.size(), &name_string)) {
+ std::cerr << "String_NewUTF8 Failed'" << className << "'" << std::endl;
+ }
+ ani_int age_value(NUM_5000);
+ if (ANI_OK != env->Object_SetPropertyByName_Int(person_obj, "age", age_value)) {
+ std::cerr << "Object_SetPropertyByName_Int Failed'" << className << "'" << std::endl;
+ }
+ if (ANI_OK != env->Object_SetPropertyByName_Ref(person_obj, "name", name_string)) {
+ std::cerr << "Object_SetPropertyByName_Ref Failed'" << className << "'" << std::endl;
+ }
+ ani_int age_value_ret;
+ ani_ref name_string_ret;
+ if (ANI_OK != env->Object_GetPropertyByName_Int(person_obj, "age", &age_value_ret)) {
+ std::cerr << "Object_GetPropertyByName_Int Failed'" << className << "'" << std::endl;
+ }
+ if (ANI_OK != env->Object_GetPropertyByName_Ref(person_obj, "name", &name_string_ret)) {
+ std::cerr << "Object_GetPropertyByName_Ref Failed'" << className << "'" << std::endl;
+ }
+ return person_obj;
+}
+
+ani_int BindGet([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object object)
+{
+ ani_int rs;
+ const char *fieldName = "_thisIsProperty";
+ env->Object_GetFieldByName_Int(object, fieldName, &rs);
+ return rs;
+}
+
+void BindSet([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object object, ani_int i)
+{
+ const char *fieldName = "_thisIsProperty";
+ env->Object_SetFieldByName_Int(object, fieldName, i);
+ return;
+}
\ No newline at end of file
diff --git a/code/ArkTS1.2/ANISample/entry/src/main/cpp/ani_string.cpp b/code/ArkTS1.2/ANISample/entry/src/main/cpp/ani_string.cpp
index 5a97a096a35628a7bf44ea1e5dca6902a150b085..aff8ad4f70a5312ff5d77f8dc82e81f9adbc06ef 100644
--- a/code/ArkTS1.2/ANISample/entry/src/main/cpp/ani_string.cpp
+++ b/code/ArkTS1.2/ANISample/entry/src/main/cpp/ani_string.cpp
@@ -24,26 +24,18 @@
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "ani/ani.h"
-#include "hilog/log.h"
#include
-#undef LOG_DOMAIN
-#undef LOG_TAG
-#define LOG_DOMAIN 0x3200 // 全局domain宏,标识业务领域
-#define LOG_TAG "MY_TAG" // 全局tag宏,标识模块日志tag
-// String Operations
-
static ani_string String_Operations(ani_env *env, [[maybe_unused]] ani_object obj)
{
std::string msg = "testTag this message in cpp";
ani_string ani_str;
+ ani_size strSize;
if (ANI_OK != env->String_NewUTF8(msg.c_str(), msg.size(), &ani_str)) {
std::cerr << "String_NewUTF8 fail" << std::endl;
}
- ani_size strSize;
if (ANI_OK != env->String_GetUTF8Size(ani_str, &strSize)) {
std::cerr << "String_NewUTF8 fail" << std::endl;
}
- OH_LOG_ERROR(LOG_APP, "testTag String_GetUTF8Size result: %{public}ld", strSize);
return ani_str;
}
\ No newline at end of file
diff --git a/code/ArkTS1.2/ANISample/entry/src/main/cpp/ani_vminterface.cpp b/code/ArkTS1.2/ANISample/entry/src/main/cpp/ani_vminterface.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..d3bea18aa84b3213fbce00aa0965763a34a9924d
--- /dev/null
+++ b/code/ArkTS1.2/ANISample/entry/src/main/cpp/ani_vminterface.cpp
@@ -0,0 +1,37 @@
+/**
+ *
+ * Copyright (c) 2025 Huawei Device Co., Ltd.
+ *
+ * All rights reserved.
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice,this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * THIS IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS,
+ *
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "ani/ani.h"
+#include
+
+static ani_boolean VMInterface([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object obj)
+{
+ ani_vm *result = nullptr;
+ if (ANI_OK != env->GetVM(&result)) {
+ std::cerr << "GetVM Fail" << std::endl;
+ return false;
+ }
+ return true;
+}
\ No newline at end of file
diff --git a/code/ArkTS1.2/ANISample/entry/src/main/ets/entryability/EntryAbility.ets b/code/ArkTS1.2/ANISample/entry/src/main/ets/entryability/EntryAbility.ets
index 1c9dfb7a3b2dea0797cc8550a296cbab68159d19..a832d961a27ea4c7703487406a87ea9d19ff2c0c 100644
--- a/code/ArkTS1.2/ANISample/entry/src/main/ets/entryability/EntryAbility.ets
+++ b/code/ArkTS1.2/ANISample/entry/src/main/ets/entryability/EntryAbility.ets
@@ -27,227 +27,9 @@ import UIAbility from '@ohos.app.ability.UIAbility';
import AbilityConstant from '@ohos.app.ability.AbilityConstant';
import Want from '@ohos.app.ability.Want';
import window from '@ohos.window';
+import { BusinessError } from '@ohos.base'
import hilog from '@ohos.hilog'
-class Calc {
- native UpdateFields(): void;
-
- native UpdateFields2(): void;
-
- byteField: byte;
- charField: char;
- boolField: boolean;
- floatField: float;
- doubleField: double;
- shortField: short;
- intField: int;
- longField: long;
-
- native UpdateStaticFields(): void;
-
- native UpdateStaticFields2(): void;
-
- static intStaticField: int;
- static shortStaticField: short;
- static longStaticField: long;
- static charStaticField: char;
- static doubleStaticField: double;
- static floatStaticField: float;
- static boolStaticField: boolean;
- static byteStaticField: byte;
-
- constructor(a: int, b: double, c: boolean, f: long) {
- this.getIntField = a;
- this.getDoubleField = b;
- this.getBoolField = c;
- this.getLongField = f;
- }
-
- getDoubleField: double;
- getIntField: int;
- getBoolField: boolean;
- getShortField: short = 15;
- getLongField: long;
- getCharField: char = 'D';
- getFloatField: float = 10.23;
- getByteField: byte = 0x1;
-
- native UpdateIntFields(): int;
-
- native UpdateDoubleFields(): double;
-
- native UpdateBoolFields(): boolean;
-
- native UpdateShortFields(): short;
-
- native UpdateLongFields(): long;
-
- native UpdateCharFields(): char;
-
- native UpdateFloatFields(): float;
-
- native UpdateByteFields(): byte;
-
- fieldByName_Byte: byte;
- fieldByName_Double: double;
- fieldByName_Short: short;
- fieldByName_Float: float;
- fieldByName_Int: int;
- fieldByName_Long: long;
- fieldByName_Char: char;
- fieldByName_Bool: boolean;
-
- native UpdateByNameFields(): void;
-
- native UpdateByNameFields2(): void;
-
- native GetVersionInfo(): int;
-
- native NativeVoidFunc(): void;
-
- ManagedVoidFunc(): void {
- hilog.error(0x0000, 'testTag', "Print in ManagedVoidFunc");
- }
-
- native NativeIntFunc(): int;
-
- ManagedIntFunc(): int {
- hilog.error(0x0000, 'testTag', "Print in ManagedIntFunc");
- return 10;
- }
-
- native NativeBoolFunc(): boolean;
-
- ManagedBoolFunc(): boolean {
- hilog.error(0x0000, 'testTag', "Print in ManagedBoolFunc");
- return true;
- }
-
- native NativeShortFunc(): short;
-
- ManagedShortFunc(): short {
- hilog.error(0x0000, 'testTag', "Print in ManagedShortFunc");
- return 22;
- }
-
- native NativeLongFunc(): long;
-
- ManagedLongFunc(): long {
- hilog.error(0x0000, 'testTag', "Print in ManagedLongFunc");
- return 12365478965;
- }
-
- native NativeDoubleFunc(): double;
-
- ManagedDoubleFunc(): double {
- hilog.error(0x0000, 'testTag', "Print in ManagedDoubleFunc");
- return 12.35;
- }
-
- native NativeCharFunc(): char;
-
- ManagedCharFunc(): char {
- hilog.error(0x0000, 'testTag', "Print in ManagedCharFunc");
- return 'I';
- }
-
- native NativeFloatFunc(): float;
-
- ManagedFloatFunc(): float {
- hilog.error(0x0000, 'testTag', "Print in ManagedFloatFunc");
- return 45.32;
- }
-
- native NativeByteFunc(): byte;
-
- ManagedByteFunc(): byte {
- hilog.error(0x0000, 'testTag', "Print in ManagedByteFunc");
- return 0x1;
- }
-
- native NativeStaticFunc(): void;
-
- static ManagedStaticFunc(): void {
- hilog.error(0x0000, 'testTag', "Print in ManagedStaticFunc");
- }
-
- native NativeByNameFunc(): void;
-
- ManagedByNameVoidFunc(): void {
- hilog.error(0x0000, 'testTag', "Print in ManagedByNameVoidFunc");
- }
-
- native NativeByNameDoubleFunc(): double;
-
- ManagedByNameDoubleFunc(): double {
- hilog.error(0x0000, 'testTag', "Print in ManagedByNameDoubleFunc");
- return 3.33;
- }
-
- native NativeByNameBoolFunc(): boolean;
-
- ManagedByNameBoolFunc(): boolean {
- hilog.error(0x0000, 'testTag', "Print in ManagedByNameBoolFunc");
- return true;
- }
-
- native NativeByNameIntFunc(): int;
-
- ManagedByNameIntFunc(): int {
- hilog.error(0x0000, 'testTag', "Print in ManagedByNameIntFunc");
- return 10;
- }
-
- native NativeByNameShortFunc(): short;
-
- ManagedByNameShortFunc(): short {
- hilog.error(0x0000, 'testTag', "Print in ManagedByNameShortFunc");
- return 1456;
- }
-
- native NativeByNameLongFunc(): long;
-
- ManagedByNameLongFunc(): long {
- hilog.error(0x0000, 'testTag', "Print in ManagedByNameLongFunc");
- return 12345679852;
- }
-
- native NativeByNameCharFunc(): char;
-
- ManagedByNameCharFunc(): char {
- hilog.error(0x0000, 'testTag', "Print in ManagedByNameCharFunc");
- return 'K';
- }
-
- native NativeByNameFloatFunc(): float;
-
- ManagedByNameFloatFunc(): float {
- hilog.error(0x0000, 'testTag', "Print in ManagedByNameFloatFunc");
- return 15.655;
- }
-
- native NativeByNameByteFunc(): byte;
-
- ManagedByNameByteFunc(): byte {
- hilog.error(0x0000, 'testTag', "Print in ManagedByNameByteFunc");
- return 0x3;
- }
-
- native Global_Local_References(): void;
-
- native Weak_Global_References(): void;
-
- native VMInterface(): void;
-
- native String_Operations(): string;
-
- native HandleDoubleData(val1: double): double
-
- native ProcessArray(a: double[]): void;
-
- native ProcessArray2(a: double[]): void;
-}
-
class EntryAbility extends UIAbility {
onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
hilog.info(0x0000, 'testTag', 'EntryAbility onCreate');
@@ -256,80 +38,13 @@ class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage: window.WindowStage): void {
hilog.info(0x0000, 'testTag', 'EntryAbility onWindowStageCreate');
try {
- loadLibrary("entry")
- } catch (e: Error) {
- hilog.error(0x0000, 'testTag', 'loadFailed', e.message);
- }
- hilog.error(0x0000, 'testTag', 'AfterLoading the library');
- let cls = new Calc(20, 1.23, true, 14785236951);
- cls.UpdateFields();
- cls.UpdateFields2();
- hilog.error(0x0000, 'testTag', 'UpdateField result byteField ' + cls.byteField);
- hilog.error(0x0000, 'testTag', 'UpdateField result charField ' + cls.charField);
- hilog.error(0x0000, 'testTag', 'UpdateField result doubleField ' + cls.doubleField);
- hilog.error(0x0000, 'testTag', 'UpdateField result boolField ' + cls.boolField);
- hilog.error(0x0000, 'testTag', 'UpdateField result floatField ' + cls.floatField);
- hilog.error(0x0000, 'testTag', 'UpdateField result shortField ' + cls.shortField);
- hilog.error(0x0000, 'testTag', 'UpdateField result intField : ' + cls.intField);
- hilog.error(0x0000, 'testTag', 'UpdateField result longField ' + cls.longField);
- cls.UpdateStaticFields();
- cls.UpdateStaticFields2();
- hilog.error(0x0000, 'testTag', 'UpdateStaticFields intStaticField : ' + Calc.intStaticField);
- hilog.error(0x0000, 'testTag', 'UpdateStaticFields shortStaticField : ' + Calc.shortStaticField);
- hilog.error(0x0000, 'testTag', 'UpdateStaticFields longStaticField : ' + Calc.longStaticField);
- hilog.error(0x0000, 'testTag', 'UpdateStaticFields charStaticField : ' + Calc.charStaticField);
- hilog.error(0x0000, 'testTag', 'UpdateStaticFields intStaticField : ' + Calc.doubleStaticField);
- hilog.error(0x0000, 'testTag', 'UpdateStaticFields shortStaticField : ' + Calc.floatStaticField);
- hilog.error(0x0000, 'testTag', 'UpdateStaticFields longStaticField : ' + Calc.boolStaticField);
- hilog.error(0x0000, 'testTag', 'UpdateStaticFields charStaticField : ' + Calc.byteStaticField);
- hilog.error(0x0000, 'testTag', 'Get Ets UpdateIntFields result : ' + cls.UpdateIntFields());
- hilog.error(0x0000, 'testTag', 'Get Ets UpdateDoubleFields result : ' + cls.UpdateDoubleFields());
- hilog.error(0x0000, 'testTag', 'Get Ets UpdateBoolFields result : ' + cls.UpdateBoolFields());
- hilog.error(0x0000, 'testTag', 'Get Ets UpdateShortFields result : ' + cls.UpdateShortFields());
- hilog.error(0x0000, 'testTag', 'Get Ets UpdateLongFields result : ' + cls.UpdateLongFields());
- hilog.error(0x0000, 'testTag', 'Get Ets UpdateCharFields result : ' + cls.UpdateCharFields());
- hilog.error(0x0000, 'testTag', 'Get Ets UpdateFloatFields result : ' + cls.UpdateFloatFields());
- hilog.error(0x0000, 'testTag', 'Get Ets UpdateByteFields result : ' + cls.UpdateByteFields());
- cls.NativeVoidFunc();
- cls.NativeBoolFunc();
- cls.NativeIntFunc();
- cls.NativeLongFunc();
- cls.NativeDoubleFunc();
- cls.NativeFloatFunc();
- cls.NativeCharFunc();
- cls.NativeByteFunc();
- cls.NativeStaticFunc();
- cls.UpdateByNameFields();
- cls.UpdateByNameFields2();
- hilog.error(0x0000, 'testTag', 'UpdateByNameFields result fieldByName_Bytes ' + cls.fieldByName_Byte);
- hilog.error(0x0000, 'testTag', 'UpdateByNameFields result fieldByName_Double ' + cls.fieldByName_Double);
- hilog.error(0x0000, 'testTag', 'UpdateByNameFields result fieldByName_Short ' + cls.fieldByName_Short);
- hilog.error(0x0000, 'testTag', 'UpdateByNameFields result fieldByName_Bool ' + cls.fieldByName_Bool);
- hilog.error(0x0000, 'testTag', 'UpdateByNameFields result fieldByName_Float ' + cls.fieldByName_Float);
- hilog.error(0x0000, 'testTag', 'UpdateByNameFields result fieldByName_Int ' + cls.fieldByName_Int);
- hilog.error(0x0000, 'testTag', 'UpdateByNameFields result fieldByName_Long ' + cls.fieldByName_Long);
- hilog.error(0x0000, 'testTag', 'UpdateByNameFields result fieldByName_Char ' + cls.fieldByName_Char);
- hilog.error(0x0000, 'testTag', 'GetVersionInfo result : ' + cls.GetVersionInfo());
- cls.Global_Local_References();
- cls.Weak_Global_References();
- cls.NativeByNameFunc();
- hilog.error(0x0000, 'testTag', 'NativeByNameDoubleFunc() result ' + cls.NativeByNameDoubleFunc());
- hilog.error(0x0000, 'testTag', 'NativeByNameBoolFunc() result ' + cls.NativeByNameBoolFunc());
- hilog.error(0x0000, 'testTag', 'NativeByNameIntFunc() result ' + cls.NativeByNameIntFunc());
- hilog.error(0x0000, 'testTag', 'NativeByNameShortFunc() result ' + cls.NativeByNameShortFunc());
- hilog.error(0x0000, 'testTag', 'NativeByNameLongFunc() result ' + cls.NativeByNameLongFunc());
- hilog.error(0x0000, 'testTag', 'NativeByNameCharFunc() result ' + cls.NativeByNameCharFunc());
- hilog.error(0x0000, 'testTag', 'NativeByNameFloatFunc() result ' + cls.NativeByNameFloatFunc());
- hilog.error(0x0000, 'testTag', 'NativeByNameByteFunc() result ' + cls.NativeByNameByteFunc());
- hilog.error(0x0000, 'testTag', 'HandleDoubleData() result ' + cls.HandleDoubleData(15));
- hilog.error(0x0000, 'testTag', 'String_Operations result : ' + cls.String_Operations())
- let s: double[] = [5, 15, 20];
- cls.ProcessArray(s);
- cls.ProcessArray2(s);
-
- try {
- windowStage.loadContent('pages/Index', (err: Error): void => {
+ windowStage.loadContent('pages/Index', (err: BusinessError): void => {
hilog.info(0x0000, 'testTag', 'loadContent entering');
+ if (err.code) {
+ hilog.info(0x0000, 'testTag', 'loadContent error');
+ return;
+ }
+ hilog.info(0x0000, 'testTag', 'loadContent ok');
});
} catch (e: Error) {
hilog.info(0x0000, 'testTag', 'loadContent catch error:-----------' + e.message);
diff --git a/code/ArkTS1.2/ANISample/entry/src/main/ets/pages/Index.ets b/code/ArkTS1.2/ANISample/entry/src/main/ets/pages/Index.ets
index aa9a598eee61c2ae46ea198c7cfc523c484cd0db..2fdad5f7f8ad728aa9399d46512777f468af5b53 100644
--- a/code/ArkTS1.2/ANISample/entry/src/main/ets/pages/Index.ets
+++ b/code/ArkTS1.2/ANISample/entry/src/main/ets/pages/Index.ets
@@ -23,37 +23,678 @@
*
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import { Text } from "@koalaui.arkts-arkui.Text"
-import { Column } from "@koalaui.arkts-arkui.Column"
-import { Button } from "@koalaui.arkts-arkui.Button"
-import { Component } from "@koalaui.arkts-arkui.Common"
-import { UserView, UserViewBuilder } from "@koalaui.arkts-arkui.UserView"
-import { __memo_context_type, __memo_id_type } from "@ohos.arkui.StateManagement.runtime"
+import { memo, __memo_context_type, __memo_id_type } from '@ohos.arkui.stateManagement'
+import {
+ Text,
+ TextAttribute,
+ Column,
+ Component,
+ Button,
+ ButtonAttribute,
+ ClickEvent,
+ UserView,
+ Entry,
+ List,
+ Margin,FlexAlign
+} from '@ohos.arkui.component'
+import { State, StateDecoratedVariable, MutableState, stateOf, observableProxy } from '@ohos.arkui.stateManagement'
import hilog from '@ohos.hilog'
+export class Want {
+ public value: int;
+
+ public constructor(v: int) {
+ this.value = v;
+ }
+}
+
+interface Person {
+ name: string;
+ age: int;
+}
+
+let intNum: int = 15;
+let floatNum: float = 10.02;
+let doubleNum: double = 12.333;
+let shortNum: short = 199;
+let longNum: long = 12345678910;
+let charNum: char = 65;
+let byteNum: byte = 0x3;
+
+class Calc implements Person {
+ name: string = '';
+ age: int = 2;
+ thisIsField: int = 3;
+ _thisIsProperty: int = 10;
+ native static createPerson(): Calc;
+
+ native thisIsPropertyGetter(): int;
+
+ native thisIsPropertySetter(i: int): void;
+
+ get thisIsProperty(): int {
+ return this.thisIsPropertyGetter();
+ }
+
+ set thisIsProperty(i: int) {
+ this.thisIsPropertySetter(i);
+ return;
+ }
+
+ native UpdateFields(): void;
+
+ native UpdateFields2(): void;
+
+ native execute(want: Want): int;
+
+ native gettid(): int;
+
+ promiseNum: int = 10;
+
+ startAbility(want: Want): Promise {
+ hilog.info(0x0000, 'testTag', 'Start Ability in thread ' + this.gettid() + '.');
+ let p = new Promise((resolve: (v: int) => void, reject: (error: Error) => void) => {
+ let cb = (): Int => {
+ this.execute(want);
+ return this.promiseNum;
+ }
+ let p1 = taskpool.execute(cb);
+ p1.then((e: NullishType) => {
+ hilog.info(0x0000, 'testTag', 'P1 then in thread ' + this.gettid() + '.');
+ hilog.info(0x0000, 'testTag', 'P1 then e = ' + e + '.');
+ let r: Int = e as Int;
+ resolve(r.unboxed());
+ });
+ hilog.info(0x0000, 'testTag', 'Promise execute in thread ' + this.gettid() + '.');
+ });
+ return p;
+ }
+
+ byteField: byte;
+ charField: char;
+ boolField: boolean;
+ floatField: float;
+ doubleField: double;
+ shortField: short;
+ intField: int;
+ longField: long;
+ native UpdateStaticFields(): void;
+
+ native UpdateStaticFields2(): void;
+
+ native GetStaticFields(): boolean;
+
+ native GetStaticFields2(): boolean;
+
+ static intStaticField: int;
+ static shortStaticField: short;
+ static longStaticField: long;
+ static charStaticField: char;
+ static doubleStaticField: double;
+ static floatStaticField: float;
+ static boolStaticField: boolean;
+ static byteStaticField: byte;
+ fieldByName_Byte: byte;
+ fieldByName_Double: double;
+ fieldByName_Short: short;
+ fieldByName_Float: float;
+ fieldByName_Int: int;
+ fieldByName_Long: long;
+ fieldByName_Char: char;
+ fieldByName_Bool: boolean;
+ native UpdateByNameFields(): void;
+
+ native UpdateByNameFields2(): void;
+
+ native GetVersionInfo(): int;
+
+ native NativeVoidFunc(): void;
+
+ ManagedVoidFunc(): void {
+ }
+
+ native NativeIntFunc(): int;
+
+ ManagedIntFunc(): int {
+ return ++intNum;
+ }
+
+ native NativeBoolFunc(): boolean;
+
+ ManagedBoolFunc(): boolean {
+ return true;
+ }
+
+ native NativeShortFunc(): short;
+
+ ManagedShortFunc(): short {
+ return ++shortNum;
+ }
+
+ native NativeLongFunc(): long;
+
+ ManagedLongFunc(): long {
+ return ++longNum;
+ }
+
+ native NativeDoubleFunc(): double;
+
+ ManagedDoubleFunc(): double {
+ return ++doubleNum;
+ }
+
+ native NativeCharFunc(): char;
+
+ ManagedCharFunc(): char {
+ return ++charNum;
+ }
+
+ native NativeFloatFunc(): float;
+
+ ManagedFloatFunc(): float {
+ return ++floatNum;
+ }
+
+ native NativeByteFunc(): byte;
+
+ ManagedByteFunc(): byte {
+ return ++byteNum;
+ }
+
+ native NativeStaticFunc(): void;
+
+ static ManagedStaticFunc(): void {
+ }
+
+ native NativeStaticFuncDouble(): double;
+
+ static ManagedStaticFuncDouble(): double {
+ return ++doubleNum;
+ }
+
+ native NativeStaticFuncFloat(): float;
+
+ static ManagedStaticFuncFloat(): float {
+ return ++floatNum;
+ }
+
+ native NativeStaticFuncByte(): byte;
+
+ static ManagedStaticFuncByte(): byte {
+ return ++byteNum;
+ }
+
+ native NativeStaticFuncChar(): char;
+
+ static ManagedStaticFuncChar(): char {
+ return ++charNum;
+ }
+
+ native NativeStaticFuncBoolean(): boolean;
+
+ static ManagedStaticFuncBoolean(): boolean {
+ return true;
+ }
+
+ native NativeStaticFuncInt(): int;
+
+ static ManagedStaticFuncInt(): int {
+ return ++intNum;
+ }
+
+ native NativeStaticFuncShort(): short;
+
+ static ManagedStaticFuncShort(): short {
+ return ++shortNum;
+ }
+
+ native NativeStaticFuncLong(): long;
+
+ static ManagedStaticFuncLong(): long {
+ return ++longNum;
+ }
+
+ native NativeByNameFunc(): void;
+
+ ManagedByNameVoidFunc(): void {
+ }
+
+ native NativeByNameDoubleFunc(): double;
+
+ ManagedByNameDoubleFunc(): double {
+ return ++doubleNum;
+ }
+
+ native NativeByNameBoolFunc(): boolean;
+
+ ManagedByNameBoolFunc(): boolean {
+ return true;
+ }
+
+ native NativeByNameIntFunc(): int;
+
+ ManagedByNameIntFunc(): int {
+ return ++intNum;
+ }
+
+ native NativeByNameShortFunc(): short;
+
+ ManagedByNameShortFunc(): short {
+ return ++shortNum;
+ }
+
+ native NativeByNameLongFunc(): long;
+
+ ManagedByNameLongFunc(): long {
+ return ++longNum;
+ }
+
+ native NativeByNameCharFunc(): char;
+
+ ManagedByNameCharFunc(): char {
+ return ++charNum;
+ }
+
+ native NativeByNameFloatFunc(): float;
+
+ ManagedByNameFloatFunc(): float {
+ return ++floatNum;
+ }
+
+ native NativeByNameByteFunc(): byte;
+
+ ManagedByNameByteFunc(): byte {
+ return ++byteNum;
+ }
+
+ native Global_Local_References(): boolean;
+
+ native Weak_Global_References(): boolean;
+
+ native VMInterface(): boolean;
+
+ native String_Operations(): string;
+
+ native HandleDoubleData(val1: double): double;
+
+ native ProcessArray(a: double[]): boolean;
+
+ native ProcessArray2(a: double[]): boolean;
+
+ native ThrowError(error: Error): boolean;
+}
+
+class CustomError extends Error {
+ constructor(message: string) {
+ super(message);
+ this.name = 'CustomError'; // 设置错误名称
+ }
+}
+
@Component
struct MyStateSample {
+ @State stateVar: string = 'state var';
+ message: string = 'var';
+
+ changeValue(): void {
+ this.stateVar += '~'
+ }
+
+ @State versionInfo: int = 0;
+ @State globalLocalReferences: boolean = false;
+ @State weakGlobalReferences: boolean = false;
+ @State vmInterface: boolean = false;
+ @State stringOperation: string = '';
+ @State stringExceptions: string = '';
+ @State processArray: boolean = false;
+ @State processArray2: boolean = false;
+ @State objectOperation: double = 0;
+ @State intStaticField: int = 0;
+ @State shortStaticField: short = 0;
+ @State longStaticField: long = 0;
+ @State charStaticField: char = 0x0;
+ @State doubleStaticField: double = 0.0;
+ @State floatStaticField: float = 0.0;
+ @State boolStaticField: boolean = false;
+ @State byteStaticField: byte = 0x0;
+ @State byteField: byte = 0x0;
+ @State charField: char = 0x0;
+ @State boolField: boolean = false;
+ @State floatField: float = 0.0;
+ @State doubleField: double = 0.0;
+ @State shortField: short = 0;
+ @State intField: int = 0;
+ @State longField: long = 0;
+ @State fieldByName_Byte: byte = 0x0;
+ @State fieldByName_Double: double = 0.0;
+ @State fieldByName_Short: short = 0;
+ @State fieldByName_Float: float = 0.0;
+ @State fieldByName_Int: int = 0;
+ @State fieldByName_Long: long = 0;
+ @State fieldByName_Char: char = 0x0;
+ @State fieldByName_Bool: boolean = false;
+ @State getStaticFields: boolean = false;
+ @State getStaticFields2: boolean = false;
+ @State callingsByteValue: byte = 0x0;
+ @State callingsDoubleValue: double = 0.0;
+ @State callingsShortValue: short = 0;
+ @State callingsFloatValue: float = 0.0;
+ @State callingsIntValue: int = 0;
+ @State callingsLongValue: long = 0;
+ @State callingsCharValue: char = 0x0;
+ @State callingsBoolValue: boolean = false;
+ @State callingsStaticByteValue: byte = 0x0;
+ @State callingsStaticDoubleValue: double = 0.0;
+ @State callingsStaticShortValue: short = 0;
+ @State callingsStaticFloatValue: float = 0.0;
+ @State callingsStaticIntValue: int = 0;
+ @State callingsStaticLongValue: long = 0;
+ @State callingsStaticCharValue: char = 0x0;
+ @State callingsStaticBoolValue: boolean = false;
+ @State classByteValue: byte = 0x0;
+ @State classDoubleValue: double = 0.0;
+ @State classShortValue: short = 0;
+ @State classFloatValue: float = 0.0;
+ @State classIntValue: int = 0;
+ @State classLongValue: long = 0;
+ @State classCharValue: char = 0x0;
+ @State classBoolValue: boolean = false;
+ @State reflectionAge: int = 0;
+ @State reflectionIsField: int = 0;
+ @State reflectionIsProperty: int = 0;
+ @State reflectionName: string = '';
+ @State loadFlag: boolean = false;
+ @State promiseFlag: boolean = false;
+
build() {
- Column() {
- Text("Hello World!")
- Button('change')
- }
+ Column(undefined) {
+ List() {
+ Button('load AniTest').onClick((e: ClickEvent) => {
+ try {
+ loadLibrary('aniTest');
+ this.loadFlag = true;
+ } catch (e: Error) {
+ hilog.error(0x0000, 'testTag', e.message)
+ this.loadFlag = false;
+ }
+ }).width('80%')
+ Text('load AniTest : ' + (this.loadFlag ? 'success' : 'fail'))
+ .fontSize(18)
+ .margin({ top: 10, bottom: 10 } as Margin)
+ Button('Version Info').backgroundColor('#ff00e1ff').width('80%')
+ .onClick((e: ClickEvent) => {
+ if (!this.loadFlag) {
+ return;
+ }
+ const cls = new Calc();
+ this.versionInfo = cls.GetVersionInfo();
+ })
+ Text('Version Info: ' + this.versionInfo).fontSize(18).margin({ bottom: 10 } as Margin)
+ Button('Global and Local References').backgroundColor('#ff00e1ff').width('80%')
+ .onClick((e: ClickEvent) => {
+ if (!this.loadFlag) {
+ return;
+ }
+ const cls = new Calc();
+ this.globalLocalReferences = cls.Global_Local_References();
+ })
+ Text('Global and Local References create : ' + this.globalLocalReferences).fontSize(18).margin({ bottom: 10 } as Margin)
+ Button('Weak Global References').backgroundColor('#ff00e1ff').width('80%')
+ .onClick((e: ClickEvent) => {
+ if (!this.loadFlag) {
+ return;
+ }
+ const cls = new Calc();
+ this.weakGlobalReferences = cls.Weak_Global_References();
+ })
+ Text('Weak Global References create : ' + this.weakGlobalReferences).fontSize(18).margin({ bottom: 10 } as Margin)
+ Button('String Operations').backgroundColor('#ff00e1ff').width('80%')
+ .onClick((e: ClickEvent) => {
+ if (!this.loadFlag) {
+ return;
+ }
+ const cls = new Calc();
+ this.stringOperation = cls.String_Operations();
+ })
+ Text('String Operations : ' + this.stringOperation).fontSize(18).margin({ bottom: 10 } as Margin)
+ Button('Promise ').backgroundColor('#ff00e1ff').width('80%')
+ .onClick((e: ClickEvent) => {
+ if (!this.loadFlag) {
+ return;
+ }
+ const cls = new Calc();
+ let want = new Want(42);
+ let p = cls.startAbility(want);
+ p.then((value: int): void => {
+ if (value != 10) {
+ hilog.info(0x0000, 'testTag',
+ 'Test failed. The promise shoule be fulfilled by 10 but got ' + value + '.');
+ this.promiseFlag = false;
+ return;
+ }
+ this.promiseFlag = true;
+ hilog.info(0x0000, 'testTag', 'Test passed.');
+ }, (err: Object): void => {
+ hilog.info(0x0000, 'testTag', 'Test failed. The promise shouldn`t be rejected.');
+ });
+ })
+ Text('Promise : ' + (this.promiseFlag ? 'Test passed.' : 'Test failed. The promise shouldn`t be rejected.'))
+ .fontSize(18).margin({ bottom: 10 } as Margin)
+ Button('Array Operations : ').backgroundColor('#ff00e1ff').width('80%')
+ .onClick((e: ClickEvent) => {
+ if (!this.loadFlag) {
+ return;
+ }
+ const cls = new Calc();
+ let s: double[] = [5, 15, 18];
+ this.processArray = cls.ProcessArray(s);
+ let s2: double[] = [5, 15, 20, 25, 30];
+ this.processArray2 = cls.ProcessArray2(s2);
+ })
+ Text('Array_New_XX create: ' + this.processArray).fontSize(18)
+ Text('Array_New_XX create2: ' + this.processArray2).fontSize(18).margin({ bottom: 10 } as Margin)
+ Button('Object Operations : ').backgroundColor('#ff00e1ff').width('80%')
+ .onClick((e: ClickEvent) => {
+ if (!this.loadFlag) {
+ return;
+ }
+ const cls = new Calc();
+ this.objectOperation = cls.HandleDoubleData(15);
+ })
+ Text('Object_Operations double value: ' + this.objectOperation).fontSize(18).margin({ bottom: 10 } as Margin)
+ Button('VM_Interface : ').backgroundColor('#ff00e1ff').width('80%')
+ .onClick((e: ClickEvent) => {
+ if (!this.loadFlag) {
+ return;
+ }
+ const cls = new Calc();
+ this.vmInterface = cls.VMInterface();
+ })
+ Text('VM_Interface GetVm : ' + this.vmInterface).fontSize(18).margin({ bottom: 10 } as Margin)
+ Button('Reflection : ').backgroundColor('#ff00e1ff').width('80%')
+ .onClick((e: ClickEvent) => {
+ if (!this.loadFlag) {
+ return;
+ }
+ let cls = Calc.createPerson();
+ this.reflectionAge = cls.age;
+ this.reflectionIsField = cls.thisIsField;
+ this.reflectionName = cls.name;
+ cls.thisIsProperty = 1234567;
+ this.reflectionIsProperty = cls.thisIsProperty;
+ })
+ Text('Reflection age: ' + this.reflectionAge).fontSize(18)
+ Text('Reflection name: ' + this.reflectionName).fontSize(18)
+ Text('Reflection Field: ' + this.reflectionIsField).fontSize(18)
+ Text('Reflection Property: ' + this.reflectionIsProperty).fontSize(18).margin({ bottom: 10 } as Margin)
+ Button('Exceptions : ').backgroundColor('#ff00e1ff').width('80%')
+ .onClick((e: ClickEvent) => {
+ if (!this.loadFlag) {
+ return;
+ }
+ try {
+ const cls = new Calc();
+ const standardError = new CustomError('A standard error message');
+ let rs = cls.ThrowError(standardError);
+ } catch (e: Error) {
+ hilog.info(0x0000, 'testTag', JSON.stringify(e.message));
+ this.stringExceptions = JSON.stringify(e.message);
+ }
+ })
+ Text('Exceptions message : ' + this.stringExceptions).fontSize(18).margin({ bottom: 10 } as Margin)
+ Button('Accessing Static Fields : ').backgroundColor('#ff00e1ff').width('80%')
+ .onClick((e: ClickEvent) => {
+ if (!this.loadFlag) {
+ return;
+ }
+ const cls = new Calc();
+ cls.UpdateStaticFields();
+ cls.UpdateStaticFields2();
+ this.intStaticField = Calc.intStaticField;
+ this.shortStaticField = Calc.shortStaticField;
+ this.longStaticField = Calc.longStaticField;
+ this.charStaticField = Calc.charStaticField;
+ this.doubleStaticField = Calc.doubleStaticField;
+ this.floatStaticField = Calc.floatStaticField;
+ this.boolStaticField = Calc.boolStaticField;
+ this.byteStaticField = Calc.byteStaticField;
+ this.getStaticFields = cls.GetStaticFields();
+ this.getStaticFields2 = cls.GetStaticFields2();
+ })
+ Text('Static intStaticField : ' + this.intStaticField).fontSize(18)
+ Text('Static shortStaticField : ' + this.shortStaticField).fontSize(18)
+ Text('Static longStaticField : ' + this.longStaticField).fontSize(18)
+ Text('Static charStaticField : ' + this.charStaticField).fontSize(18)
+ Text('Static doubleStaticField : ' + this.doubleStaticField).fontSize(18)
+ Text('Static floatStaticField : ' + this.floatStaticField).fontSize(18)
+ Text('Static boolStaticField : ' + this.boolStaticField).fontSize(18)
+ Text('Static byteStaticField : ' + this.byteStaticField).fontSize(18)
+ Text('GetStaticFields : ' + this.getStaticFields).fontSize(18)
+ Text('GetStaticFields2 : ' + this.getStaticFields2).fontSize(18).margin({ bottom: 10 } as Margin)
+ Button('Accessing Fields Of Objects: ').backgroundColor('#ff00e1ff').width('80%')
+ .onClick((e: ClickEvent) => {
+ if (!this.loadFlag) {
+ return;
+ }
+ const cls = new Calc();
+ cls.UpdateFields();
+ cls.UpdateFields2();
+ this.byteField = cls.byteField;
+ this.charField = cls.charField;
+ this.doubleField = cls.doubleField;
+ this.boolField = cls.boolField;
+ this.floatField = cls.floatField;
+ this.shortField = cls.shortField;
+ this.intField = cls.intField;
+ this.longField = cls.longField;
+ cls.UpdateByNameFields();
+ cls.UpdateByNameFields2();
+ this.fieldByName_Byte = cls.fieldByName_Byte;
+ this.fieldByName_Double = cls.fieldByName_Double;
+ this.fieldByName_Short = cls.fieldByName_Short;
+ this.fieldByName_Float = cls.fieldByName_Float;
+ this.fieldByName_Int = cls.fieldByName_Int;
+ this.fieldByName_Long = cls.fieldByName_Long;
+ this.fieldByName_Char = cls.fieldByName_Char;
+ this.fieldByName_Bool = cls.fieldByName_Bool;
+ })
+ Text('Fields byteField: ' + this.byteField).fontSize(18)
+ Text('Fields charField: ' + this.charField).fontSize(18)
+ Text('Fields doubleField: ' + this.doubleField).fontSize(18)
+ Text('Fields boolField: ' + this.boolField).fontSize(18)
+ Text('Fields floatField: ' + this.floatField).fontSize(18)
+ Text('Fields shortField: ' + this.shortField).fontSize(18)
+ Text('Fields intField: ' + this.intField).fontSize(18)
+ Text('Fields longField: ' + this.longField).fontSize(18)
+ Text('Fields fieldByName_Byte: ' + this.fieldByName_Byte).fontSize(18)
+ Text('Fields fieldByName_Double: ' + this.fieldByName_Double).fontSize(18)
+ Text('Fields fieldByName_Short: ' + this.fieldByName_Short).fontSize(18)
+ Text('Fields fieldByName_Float: ' + this.fieldByName_Float).fontSize(18)
+ Text('Fields fieldByName_Int: ' + this.fieldByName_Int).fontSize(18)
+ Text('Fields fieldByName_Long: ' + this.fieldByName_Long).fontSize(18)
+ Text('Fields fieldByName_Char: ' + this.fieldByName_Char).fontSize(18)
+ Text('Fields fieldByName_Bool: ' + this.fieldByName_Bool).fontSize(18).margin({ bottom: 10 } as Margin)
+ Button('Class Operations : ').backgroundColor('#ff00e1ff').width('80%')
+ .onClick((e: ClickEvent) => {
+ if (!this.loadFlag) {
+ return;
+ }
+ const cls = new Calc();
+ this.classByteValue = cls.NativeByteFunc();
+ this.classFloatValue = cls.NativeFloatFunc();
+ this.classDoubleValue = cls.NativeDoubleFunc();
+ this.classCharValue = cls.NativeCharFunc();
+ this.classIntValue = cls.NativeIntFunc();
+ this.classShortValue = cls.NativeShortFunc();
+ this.classLongValue = cls.NativeLongFunc();
+ this.classBoolValue = cls.NativeBoolFunc();
+ })
+ Text('classByteValue : ' + this.classByteValue).fontSize(18)
+ Text('classFloatValue : ' + this.classFloatValue).fontSize(18)
+ Text('classDoubleValue : ' + this.classDoubleValue).fontSize(18)
+ Text('classCharValue : ' + this.classCharValue).fontSize(18)
+ Text('classIntValue : ' + this.classIntValue).fontSize(18)
+ Text('classShortValue : ' + this.classShortValue).fontSize(18)
+ Text('classLongValue : ' + this.classLongValue).fontSize(18)
+ Text('classBoolValue : ' + this.classBoolValue).fontSize(18).margin({ bottom: 10 } as Margin)
+ Button('Calling Instance Methods : ').backgroundColor('#ff00e1ff').width('80%')
+ .onClick((e: ClickEvent) => {
+ if (!this.loadFlag) {
+ return;
+ }
+ const cls = new Calc();
+ cls.NativeByNameFunc();
+ this.callingsByteValue = cls.NativeByNameByteFunc();
+ this.callingsDoubleValue = cls.NativeByNameDoubleFunc();
+ this.callingsShortValue = cls.NativeByNameShortFunc();
+ this.callingsFloatValue = cls.NativeByNameFloatFunc();
+ this.callingsIntValue = cls.NativeByNameIntFunc();
+ this.callingsLongValue = cls.NativeByNameLongFunc();
+ this.callingsCharValue = cls.NativeByNameCharFunc();
+ this.callingsBoolValue = cls.NativeByNameBoolFunc();
+ })
+ Text('callingsByteValue : ' + this.callingsByteValue).fontSize(18)
+ Text('callingsDoubleValue : ' + this.callingsDoubleValue).fontSize(18)
+ Text('callingsShortValue : ' + this.callingsShortValue).fontSize(18)
+ Text('callingsFloatValue : ' + this.callingsFloatValue).fontSize(18)
+ Text('callingsIntValue : ' + this.callingsIntValue).fontSize(18)
+ Text('callingsLongValue : ' + this.callingsLongValue).fontSize(18)
+ Text('callingsCharValue : ' + this.callingsCharValue).fontSize(18)
+ Text('callingsBoolValue : ' + this.callingsBoolValue).fontSize(18).margin({ bottom: 10 } as Margin)
+ Button('Calling Static Methods : ').backgroundColor('#ff00e1ff').width('80%')
+ .onClick((e: ClickEvent) => {
+ if (!this.loadFlag) {
+ return;
+ }
+ const cls = new Calc();
+ this.callingsStaticDoubleValue = cls.NativeStaticFuncDouble();
+ this.callingsStaticFloatValue = cls.NativeStaticFuncFloat();
+ this.callingsStaticByteValue = cls.NativeStaticFuncByte();
+ this.callingsStaticCharValue = cls.NativeStaticFuncChar();
+ this.callingsStaticBoolValue = cls.NativeStaticFuncBoolean();
+ this.callingsStaticIntValue = cls.NativeStaticFuncInt();
+ this.callingsStaticShortValue = cls.NativeStaticFuncShort();
+ this.callingsStaticLongValue = cls.NativeStaticFuncLong();
+ })
+ Text('callingsStaticDoubleValue : ' + this.callingsStaticDoubleValue).fontSize(18)
+ Text('callingsStaticFloatValue : ' + this.callingsStaticFloatValue).fontSize(18)
+ Text('callingsStaticByteValue : ' + this.callingsStaticByteValue).fontSize(18)
+ Text('callingsStaticCharValue : ' + this.callingsStaticCharValue).fontSize(18)
+ Text('callingsStaticBoolValue : ' + this.callingsStaticBoolValue).fontSize(18)
+ Text('callingsStaticIntValue : ' + this.callingsStaticIntValue).fontSize(18)
+ Text('callingsStaticShortValue : ' + this.callingsStaticShortValue).fontSize(18)
+ Text('callingsStaticLongValue : ' + this.callingsStaticLongValue).fontSize(18).margin({ bottom: 10 } as Margin)
+ }.margin({ left: '20%' } as Margin)
+ }.width('100%')
}
}
export class ComExampleTrivialApplication extends UserView {
- getBuilder(): UserViewBuilder {
- hilog.info(0x0000, 'testTag', 'ComExampleTrivialApplication');
- let wrapper = (__memo_context: __memo_context_type, __memo_id: __memo_id_type) => {
- hilog.info(0x0000, 'testTag', 'MyStateSample.instantiateImpl');
- MyStateSample.instantiateImpl(
- undefined,
- (): MyStateSample => new MyStateSample(),
- {} as __Options_MyStateSample,
- undefined
- )
+ getBuilder() {
+ let wrapper = @memo() =>{
+ hilog.info(0x0000, 'testTag', 'MyStateSample');
+ MyStateSample(undefined);
}
- hilog.info(0x0000, 'testTag', 'getBuilder.end');
- return wrapper
+ return wrapper;
}
}
\ No newline at end of file
diff --git a/code/ArkTS1.2/ANISample/entry/src/main/resources/base/media/aniTest.PNG b/code/ArkTS1.2/ANISample/entry/src/main/resources/base/media/aniTest.PNG
new file mode 100644
index 0000000000000000000000000000000000000000..7ea0b449b05f9315c3eaa981f759b41713824211
Binary files /dev/null and b/code/ArkTS1.2/ANISample/entry/src/main/resources/base/media/aniTest.PNG differ
diff --git a/code/ArkTS1.2/ANISample/entry/src/main/resources/base/media/aniTest2.PNG b/code/ArkTS1.2/ANISample/entry/src/main/resources/base/media/aniTest2.PNG
new file mode 100644
index 0000000000000000000000000000000000000000..5ec0d10aa807d56c760edfbee545868546b6bae0
Binary files /dev/null and b/code/ArkTS1.2/ANISample/entry/src/main/resources/base/media/aniTest2.PNG differ
diff --git a/code/ArkTS1.2/ANISample/entry/src/main/resources/base/media/aniTest3.PNG b/code/ArkTS1.2/ANISample/entry/src/main/resources/base/media/aniTest3.PNG
new file mode 100644
index 0000000000000000000000000000000000000000..5f475ad0d8386600dccb004c8608555d9aaed53f
Binary files /dev/null and b/code/ArkTS1.2/ANISample/entry/src/main/resources/base/media/aniTest3.PNG differ
diff --git a/code/ArkTS1.2/ANISample/hvigor/hvigor-config.json5 b/code/ArkTS1.2/ANISample/hvigor/hvigor-config.json5
index 85e8d4b2175fc4747650344f025e7d145bc3d361..58a9aa9da11e3d503564bb6eb1a7819132dd2b38 100644
--- a/code/ArkTS1.2/ANISample/hvigor/hvigor-config.json5
+++ b/code/ArkTS1.2/ANISample/hvigor/hvigor-config.json5
@@ -1,5 +1,5 @@
{
- "modelVersion": "5.1.0",
+ "modelVersion": "6.0.0",
"dependencies": {
},
"execution": {
@@ -19,4 +19,4 @@
// "maxOldSpaceSize": 8192 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process. Default: 8192*/
// "exposeGC": true /* Enable to trigger garbage collection explicitly. Default: true*/
}
-}
+}
\ No newline at end of file
diff --git a/code/ArkTS1.2/ANISample/oh-package.json5 b/code/ArkTS1.2/ANISample/oh-package.json5
index 7f512c9632708e85a7ea34e739c01b0b8f1ad92e..63c4d97bf87c63a5128c056093abdec405e6f145 100644
--- a/code/ArkTS1.2/ANISample/oh-package.json5
+++ b/code/ArkTS1.2/ANISample/oh-package.json5
@@ -1,8 +1,10 @@
{
- "modelVersion": "5.1.0",
+ "modelVersion": "6.0.0",
"description": "Please describe the basic information.",
"dependencies": {
},
"devDependencies": {
+ "@ohos/hypium": "1.0.21",
+ "@ohos/hamock": "1.0.1-rc2"
}
-}
+}
\ No newline at end of file
diff --git a/code/ArkTS1.2/ANISample/ohosTest.md b/code/ArkTS1.2/ANISample/ohosTest.md
new file mode 100644
index 0000000000000000000000000000000000000000..d4778cba7cb4f7ef28879dbf8e98fc75e311dd07
--- /dev/null
+++ b/code/ArkTS1.2/ANISample/ohosTest.md
@@ -0,0 +1,21 @@
+# ArkTS和C++相互调用测试用例
+
+## 用例表
+
+| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 |
+|-----------------------------------|-------------------------------------|----------------------|------------------------------------|------|------|
+| ArkTS调用C++获取版本信息验证(Version Info) | 1. 需在真机测试
2. 构建并安装测试hap
3.打开测试hap,点击首页load AniTtest 显示sucess| 1、点击Version Info按钮 | 1、下方日志打印以下信息:
Version Info : 1 | 否 | Pass |
+| 全局/局部引用验证(Global and Local References) | 1. 需在真机测试
2. 构建并安装测试hap
3.打开测试hap,点击首页load AniTtest 显示sucess| 1、点击Global and Local References按钮 | 1、下方日志打印以下信息:
Global and Local References create :true | 否 | Pass |
+| 弱全局引用验证(Weak Global References) | 1. 需在真机测试
2. 构建并安装测试hap
3.打开测试hap,点击首页load AniTtest 显示sucess| 1、点击Weak Global References按钮 | 1、下方日志打印以下信息:
Weak Global References create :true | 否 | Pass |
+| 字符串验证(String Operations ) | 1. 需在真机测试
2. 构建并安装测试hap
3.打开测试hap,点击首页load AniTtest 显示sucess| 1、点击String Operations按钮 | 1、下方日志打印以下信息:
“testTag this message in cpp” | 否 | Pass |
+| ArkTS和C++异步调用验证(Promise) | 1. 需在真机测试
2. 构建并安装测试hap
3.打开测试hap,点击首页load AniTtest 显示sucess| 1、点击Promise按钮 | 1、下方日志打印以下信息:
Promise :Test passed. | 否 | Pass |
+| 数组操作验证(Array Operations ) | 1. 需在真机测试
2. 构建并安装测试hap
3.打开测试hap,点击首页load AniTtest 显示sucess| 1、点击Array Operations按钮 | 1、下方日志打印以下信息:
Array_New_XX create:true
Array_New_XX create2:true | 否 | Pass |
+| 操作对象验证(Object Operations) | 1. 需在真机测试
2. 构建并安装测试hap
3.打开测试hap,点击首页load AniTtest 显示sucess| 1、点击Object Operations按钮 | 1、下方日志打印以下信息:
Object_Operations double value: 15 | 否 | Pass |
+| 获取运行时环境句柄方法验证(VM_Interface) | 1. 需在真机测试
2. 构建并安装测试hap
3.打开测试hap,点击首页load AniTtest 显示sucess| 1、点击VM_Interface按钮 | 1、下方日志打印以下信息:
VM Interface GetVM :true | 否 | Pass |
+| 反射机制验证(Reflection) | 1. 需在真机测试
2. 构建并安装测试hap
3.打开测试hap,点击首页load AniTtest 显示sucess| 1、点击Reflection 按钮 | 1、下方日志打印以下信息:
Reflection age: 5000 Reflection name: China Reflection Field: 3 Reflection Property: 1234567 | 否 | Pass |
+| 抛出异常验证(Exceptions) | 1. 需在真机测试
2. 构建并安装测试hap
3.打开测试hap,点击首页load AniTtest 显示sucess| 1、点击Exceptions按钮 | 1、下方日志打印以下信息:
Exceptions message A standard error message | 否 | Pass |
+| 通过 ANI在 C/C++ 代码中调用object 类的静态实例验证(Accessing Static Fields) | 1. 需在真机测试
2. 构建并安装测试hap
3.打开测试hap,点击首页load AniTtest 显示sucess| 1、点击Accessing Static Fields按钮 | 1、下方日志打印以下信息:
Static intStaticField : 65538
Static shortStaticField :2
Static longStaticField :12345678910
Static charStaticField :U
Static doubleStaticField:15.2365941
Static floatStaticField :3.12
Static boolStaticField :true
Static byteStaticField :85
GetStaticFields : true
GetStaticFields2 : true | 否 | Pass |
+| 通过 ANI在 C/C++ 代码中调用object 类的非静态实例验证(Accessing Fields Of Objects) | 1. 需在真机测试
2. 构建并安装测试hap
3.打开测试hap,点击首页load AniTtest 显示sucess| 1、点击Accessing Fields Of Objects按钮 | 1、下方日志打印以下信息:
Fields byteField:65
Fields charField:Z
Fields doubleField:3.14
Fields boolField:true
Fields floatField: 4.56
Fields shortField: 255
Fields intField: 15
Fields longField:12345678910
Fields fieldByName_Byte:66
Fields fieldByName_Double:4.56
Fields fieldByName_Short: 255
Fields fieldByName_Float: 15.23
Fields fieldByName_Int: 120
Fields fieldByName_Long:12365478941
Fields fieldByName_Char:G
Fields fieldByName_Bool:true | 否 | Pass |
+| 操作类验证(Class Operations) | 1. 需在真机测试
2. 构建并安装测试hap
3.打开测试hap,点击首页load AniTtest 显示sucess| 1、点击Class Operations按钮 | 1、下方日志打印以下信息:(多次点击递增)
classByteValue :4
classFloatValue :11.02
classDoubleValue: 13.333
classCharValue : B
classIntValue :16
classShortValue :200
classLongValue : 12345678911
classBoolValue : true | 否 | Pass |
+| 通过 ANI在 C/C++ 代码中调用object 类的非静态方法验证(Calling Instance Methods) | 1. 需在真机测试
2. 构建并安装测试hap
3.打开测试hap,点击首页load AniTtest 显示sucess| 1、点击Calling Instance Methods按钮 | 1、下方日志打印以下信息:(多次点击递增)
callingsByteValue :5
callingsDoubleValue:14.333
callingsShortValue :201
callingsFloatValue :12.02
callingsIntValue : 17
callingsLongValue :12345678912
callingsCharValue :C
callingsBoolValue :trye | 否 | Pass |
+| 通过 ANI在 C/C++ 代码中调用object 类的静态方法验证(Calling Static Methods) | 1. 需在真机测试
2. 构建并安装测试hap
3.打开测试hap,点击首页load AniTtest 显示sucess| 1、点击Calling Static Methods按钮 | 1、下方日志打印以下信息:(多次点击递增)
callingsStaticDoubleValue15.333
callingsStaticFloatValue :13.02
callingsStaticByteValue :6
callingsStaticCharValue :D
callingsStaticBoolValue :true
callingsStaticIntValue : 18
callingsStaticShortValue :202
callingsStaticLongValue :12345678913 | 否 | Pass |
\ No newline at end of file