Skip to content

Commit

Permalink
test: setup some test
Browse files Browse the repository at this point in the history
  • Loading branch information
richerfu committed Oct 24, 2024
1 parent 9b75ac0 commit 0fe7f3a
Show file tree
Hide file tree
Showing 60 changed files with 5,894 additions and 241 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ cmake-build-debug/

*.har
package/include
*.so
14 changes: 7 additions & 7 deletions ohos_addon_example/entry/build-profile.json5
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"apiType": "stageMode",
"buildOption": {
"externalNativeOptions": {
"path": "./src/main/cpp/CMakeLists.txt",
"arguments": "",
"cppFlags": "",
}
},
// "buildOption": {
// "externalNativeOptions": {
// "path": "./src/main/cpp/CMakeLists.txt",
// "arguments": "",
// "cppFlags": "",
// }
// },
"buildOptionSet": [
{
"name": "release",
Expand Down
Empty file.
8 changes: 4 additions & 4 deletions ohos_addon_example/entry/oh-package-lock.json5

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ohos_addon_example/entry/oh-package.json5
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
"author": "",
"license": "",
"dependencies": {
"libentry.so": "file:./src/main/cpp/types/libentry"
"libexmaple.so": "file:./src/main/cpp/types/libexample"
}
}
17 changes: 2 additions & 15 deletions ohos_addon_example/entry/src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,6 @@ cmake_minimum_required(VERSION 3.5.0)
project(ohos_addon_exampl)

set(NATIVERENDER_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR})
set(NODE_ADDON_API "${CMAKE_CURRENT_SOURCE_DIR}/../../../../..")
set(EXAMPLE_DIR "${NODE_ADDON_API}/example")

file(GLOB_RECURSE SOURCES
"${EXAMPLE_DIR}/*.cpp"
"${EXAMPLE_DIR}/*.h"
"${EXAMPLE_DIR}/basic_types/*.cpp"
"${EXAMPLE_DIR}/dataview/*.cpp"
"${EXAMPLE_DIR}/object/*.cpp"
"${EXAMPLE_DIR}/threadsafe_function/*.cpp"
"${EXAMPLE_DIR}/typed_threadsafe_function/*.cpp"
)

if(DEFINED PACKAGE_FIND_FILE)
include(${PACKAGE_FIND_FILE})
Expand All @@ -23,6 +11,5 @@ endif()
include_directories(${NATIVERENDER_ROOT_PATH}
${NATIVERENDER_ROOT_PATH}/include)

add_library(entry SHARED ${SOURCES} napi_init.cpp)
target_include_directories(entry PUBLIC ${NODE_ADDON_API})
target_link_libraries(entry PUBLIC libace_napi.z.so)
add_library(example SHARED ${SOURCES} napi_init.cpp)
target_link_libraries(example PUBLIC libace_napi.z.so)
229 changes: 45 additions & 184 deletions ohos_addon_example/entry/src/main/cpp/napi_init.cpp
Original file line number Diff line number Diff line change
@@ -1,192 +1,53 @@
#include "napi.h"
#include "napi/native_api.h"

using namespace Napi;
static napi_value Add(napi_env env, napi_callback_info info)
{
size_t argc = 2;
napi_value args[2] = {nullptr};

napi_get_cb_info(env, info, &argc, args , nullptr, nullptr);

#if (NAPI_VERSION > 5)
Object InitAddon(Env env);
Object InitAddonData(Env env);
#endif
Object InitArrayBuffer(Env env);
Object InitAsyncContext(Env env);
#if (NAPI_VERSION > 3)
Object InitAsyncProgressQueueWorker(Env env);
Object InitAsyncProgressWorker(Env env);
#endif
Object InitAsyncWorker(Env env);
Object InitPersistentAsyncWorker(Env env);
Object InitBasicTypesArray(Env env);
Object InitBasicTypesBoolean(Env env);
Object InitBasicTypesNumber(Env env);
Object InitBasicTypesValue(Env env);
#if (NAPI_VERSION > 5)
Object InitBigInt(Env env);
#endif
Object InitBuffer(Env env);
Object InitBufferNoExternal(Env env);
#if (NAPI_VERSION > 2)
Object InitCallbackScope(Env env);
#endif
#if (NAPI_VERSION > 4)
Object InitDate(Env env);
#endif
Object InitCallbackInfo(Env env);
Object InitDataView(Env env);
Object InitDataViewReadWrite(Env env);
Object InitEnvCleanup(Env env);
Object InitErrorHandlingPrim(Env env);
Object InitError(Env env);
Object InitExternal(Env env);
Object InitFunction(Env env);
Object InitFunctionReference(Env env);
Object InitHandleScope(Env env);
Object InitMovableCallbacks(Env env);
//Object InitMemoryManagement(Env env);
Object InitName(Env env);
Object InitObject(Env env);
#ifndef NODE_ADDON_API_DISABLE_DEPRECATED
Object InitObjectDeprecated(Env env);
#endif // !NODE_ADDON_API_DISABLE_DEPRECATED
Object InitPromise(Env env);
//Object InitRunScript(Env env);
#if (NAPI_VERSION > 3)
Object InitThreadSafeFunctionCtx(Env env);
Object InitThreadSafeFunctionException(Env env);
Object InitThreadSafeFunctionExistingTsfn(Env env);
Object InitThreadSafeFunctionPtr(Env env);
Object InitThreadSafeFunctionSum(Env env);
Object InitThreadSafeFunctionUnref(Env env);
Object InitThreadSafeFunction(Env env);
Object InitTypedThreadSafeFunctionCtx(Env env);
Object InitTypedThreadSafeFunctionException(Env env);
Object InitTypedThreadSafeFunctionExistingTsfn(Env env);
Object InitTypedThreadSafeFunctionPtr(Env env);
Object InitTypedThreadSafeFunctionSum(Env env);
Object InitTypedThreadSafeFunctionUnref(Env env);
Object InitTypedThreadSafeFunction(Env env);
#endif
//Object InitSymbol(Env env);
Object InitTypedArray(Env env);
//Object InitGlobalObject(Env env);
Object InitObjectWrap(Env env);
Object InitObjectWrapConstructorException(Env env);
Object InitObjectWrapFunction(Env env);
Object InitObjectWrapRemoveWrap(Env env);
Object InitObjectWrapMultipleInheritance(Env env);
Object InitObjectReference(Env env);
Object InitReference(Env env);
Object InitVersionManagement(Env env);
Object InitThunkingManual(Env env);
#if (NAPI_VERSION > 7)
Object InitObjectFreezeSeal(Env env);
Object InitTypeTaggable(Env env);
#endif
#if (NAPI_VERSION > 8)
Object InitEnvMiscellaneous(Env env);
#endif
#if defined(NODE_ADDON_API_ENABLE_MAYBE)
Object InitMaybeCheck(Env env);
#endif
napi_valuetype valuetype0;
napi_typeof(env, args[0], &valuetype0);

Object EntryInit(Env env, Object exports) {
#if (NAPI_VERSION > 5)
exports.Set("addon", InitAddon(env));
exports.Set("addon_data", InitAddonData(env));
#endif
exports.Set("arraybuffer", InitArrayBuffer(env));
exports.Set("asynccontext", InitAsyncContext(env));
#if (NAPI_VERSION > 3)
exports.Set("asyncprogressqueueworker", InitAsyncProgressQueueWorker(env));
exports.Set("asyncprogressworker", InitAsyncProgressWorker(env));
#endif
// exports.Set("globalObject", InitGlobalObject(env));
exports.Set("asyncworker", InitAsyncWorker(env));
exports.Set("persistentasyncworker", InitPersistentAsyncWorker(env));
exports.Set("basic_types_array", InitBasicTypesArray(env));
exports.Set("basic_types_boolean", InitBasicTypesBoolean(env));
exports.Set("basic_types_number", InitBasicTypesNumber(env));
exports.Set("basic_types_value", InitBasicTypesValue(env));
#if (NAPI_VERSION > 5)
exports.Set("bigint", InitBigInt(env));
#endif
#if (NAPI_VERSION > 4)
exports.Set("date", InitDate(env));
#endif
exports.Set("buffer", InitBuffer(env));
exports.Set("bufferNoExternal", InitBufferNoExternal(env));
#if (NAPI_VERSION > 2)
exports.Set("callbackscope", InitCallbackScope(env));
#endif
exports.Set("callbackInfo", InitCallbackInfo(env));
exports.Set("dataview", InitDataView(env));
exports.Set("dataview_read_write", InitDataView(env));
exports.Set("dataview_read_write", InitDataViewReadWrite(env));
#if (NAPI_VERSION > 2)
exports.Set("env_cleanup", InitEnvCleanup(env));
#endif
exports.Set("error", InitError(env));
exports.Set("errorHandlingPrim", InitErrorHandlingPrim(env));
exports.Set("external", InitExternal(env));
exports.Set("function", InitFunction(env));
exports.Set("functionreference", InitFunctionReference(env));
exports.Set("name", InitName(env));
exports.Set("handlescope", InitHandleScope(env));
exports.Set("movable_callbacks", InitMovableCallbacks(env));
// exports.Set("memory_management", InitMemoryManagement(env));
exports.Set("object", InitObject(env));
#ifndef NODE_ADDON_API_DISABLE_DEPRECATED
exports.Set("object_deprecated", InitObjectDeprecated(env));
#endif // !NODE_ADDON_API_DISABLE_DEPRECATED
exports.Set("promise", InitPromise(env));
// exports.Set("symbol", InitSymbol(env));
#if (NAPI_VERSION > 3)
exports.Set("threadsafe_function_ctx", InitThreadSafeFunctionCtx(env));
exports.Set("threadsafe_function_exception",
InitThreadSafeFunctionException(env));
exports.Set("threadsafe_function_existing_tsfn",
InitThreadSafeFunctionExistingTsfn(env));
exports.Set("threadsafe_function_ptr", InitThreadSafeFunctionPtr(env));
exports.Set("threadsafe_function_sum", InitThreadSafeFunctionSum(env));
exports.Set("threadsafe_function_unref", InitThreadSafeFunctionUnref(env));
exports.Set("threadsafe_function", InitThreadSafeFunction(env));
exports.Set("typed_threadsafe_function_ctx",
InitTypedThreadSafeFunctionCtx(env));
exports.Set("typed_threadsafe_function_exception",
InitTypedThreadSafeFunctionException(env));
exports.Set("typed_threadsafe_function_existing_tsfn",
InitTypedThreadSafeFunctionExistingTsfn(env));
exports.Set("typed_threadsafe_function_ptr",
InitTypedThreadSafeFunctionPtr(env));
exports.Set("typed_threadsafe_function_sum",
InitTypedThreadSafeFunctionSum(env));
exports.Set("typed_threadsafe_function_unref",
InitTypedThreadSafeFunctionUnref(env));
exports.Set("typed_threadsafe_function", InitTypedThreadSafeFunction(env));
#endif
exports.Set("typedarray", InitTypedArray(env));
exports.Set("objectwrap", InitObjectWrap(env));
exports.Set("objectwrapConstructorException",
InitObjectWrapConstructorException(env));
exports.Set("objectwrap_function", InitObjectWrapFunction(env));
exports.Set("objectwrap_removewrap", InitObjectWrapRemoveWrap(env));
exports.Set("objectwrap_multiple_inheritance",
InitObjectWrapMultipleInheritance(env));
exports.Set("objectreference", InitObjectReference(env));
exports.Set("reference", InitReference(env));
exports.Set("version_management", InitVersionManagement(env));
exports.Set("thunking_manual", InitThunkingManual(env));
#if (NAPI_VERSION > 7)
exports.Set("object_freeze_seal", InitObjectFreezeSeal(env));
exports.Set("type_taggable", InitTypeTaggable(env));
#endif
#if (NAPI_VERSION > 8)
exports.Set("env_misc", InitEnvMiscellaneous(env));
#endif
napi_valuetype valuetype1;
napi_typeof(env, args[1], &valuetype1);

#if defined(NODE_ADDON_API_ENABLE_MAYBE)
exports.Set("maybe_check", InitMaybeCheck(env));
#endif
double value0;
napi_get_value_double(env, args[0], &value0);

double value1;
napi_get_value_double(env, args[1], &value1);

napi_value sum;
napi_create_double(env, value0 + value1, &sum);

return sum;

}

EXTERN_C_START
static napi_value Init(napi_env env, napi_value exports)
{
napi_property_descriptor desc[] = {
{ "add", nullptr, Add, nullptr, nullptr, nullptr, napi_default, nullptr }
};
napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc);
return exports;
}
EXTERN_C_END

NODE_API_MODULE(entry, EntryInit)
static napi_module demoModule = {
.nm_version = 1,
.nm_flags = 0,
.nm_filename = nullptr,
.nm_register_func = Init,
.nm_modname = "entry",
.nm_priv = ((void*)0),
.reserved = { 0 },
};

extern "C" __attribute__((constructor)) void RegisterEntryModule(void)
{
napi_module_register(&demoModule);
}
16 changes: 0 additions & 16 deletions ohos_addon_example/entry/src/main/cpp/types/libentry/Index.d.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "libentry.so",
"name": "libexmaple.so",
"types": "./Index.d.ts",
"version": "1.0.0",
"description": "Please describe the basic information."
Expand Down
5 changes: 1 addition & 4 deletions ohos_addon_example/entry/src/main/ets/pages/Index.ets
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { hilog } from '@kit.PerformanceAnalysisKit';
import * as testNapi from 'libentry.so';

@Entry
@Component
Expand All @@ -13,9 +12,7 @@ struct Index {
.fontSize(50)
.fontWeight(FontWeight.Bold)
.onClick(() => {
const a = testNapi;
const ret = testNapi.basic_types_boolean.createBoolean(false);
console.log(`${ret}`);
hilog.debug(0x0000,"","");
})
}
.width('100%')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { hilog } from '@kit.PerformanceAnalysisKit';
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium';
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from './util/framework.test';

export default function abilityTest() {
describe('ActsAbilityTest', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { describe, expect, it, DEFAULT } from '@ohos/hypium';
import testNapi, {basic_types_array} from 'libentry.so';
import { describe, expect, it, DEFAULT } from '../util/framework.test';
import binding from '../util/binding';

export default function basicTypeArray() {
describe("basic_type_array_test", () => {
it("RunArray", DEFAULT, () => {
const basic_types_array: basic_types_array = testNapi.basic_types_array;
const basic_types_array: ESObject = binding.basic_types_array;

const array = basic_types_array.createArray();
expect(basic_types_array.getLength(array)).assertEqual(0);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { describe, expect, it, DEFAULT } from '@ohos/hypium';
import testNapi, { basic_types_boolean } from 'libentry.so';
import { describe, expect, it, DEFAULT } from '../util/framework.test';
import binding from '../util/binding';

export default function basicTypeBoolean() {
describe("basic_type_boolean_test", () => {
it("RunBoolean", DEFAULT, () => {
const basic_types_boolean: basic_types_boolean = testNapi.basic_types_boolean;
const basic_types_boolean: ESObject = binding.basic_types_boolean;

expect(basic_types_boolean.createBoolean(true)).assertTrue();
expect(basic_types_boolean.createBoolean(false)).assertFalse();
Expand Down
Loading

0 comments on commit 0fe7f3a

Please sign in to comment.