Skip to content

Commit 0fe7f3a

Browse files
committed
test: setup some test
1 parent 9b75ac0 commit 0fe7f3a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+5894
-241
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ cmake-build-debug/
77

88
*.har
99
package/include
10+
*.so

ohos_addon_example/entry/build-profile.json5

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
22
"apiType": "stageMode",
3-
"buildOption": {
4-
"externalNativeOptions": {
5-
"path": "./src/main/cpp/CMakeLists.txt",
6-
"arguments": "",
7-
"cppFlags": "",
8-
}
9-
},
3+
// "buildOption": {
4+
// "externalNativeOptions": {
5+
// "path": "./src/main/cpp/CMakeLists.txt",
6+
// "arguments": "",
7+
// "cppFlags": "",
8+
// }
9+
// },
1010
"buildOptionSet": [
1111
{
1212
"name": "release",

ohos_addon_example/entry/libs/arm64-v8a/.gitkeep

Whitespace-only changes.

ohos_addon_example/entry/oh-package-lock.json5

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ohos_addon_example/entry/oh-package.json5

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
"author": "",
77
"license": "",
88
"dependencies": {
9-
"libentry.so": "file:./src/main/cpp/types/libentry"
9+
"libexmaple.so": "file:./src/main/cpp/types/libexample"
1010
}
1111
}

ohos_addon_example/entry/src/main/cpp/CMakeLists.txt

+2-15
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,6 @@ cmake_minimum_required(VERSION 3.5.0)
33
project(ohos_addon_exampl)
44

55
set(NATIVERENDER_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR})
6-
set(NODE_ADDON_API "${CMAKE_CURRENT_SOURCE_DIR}/../../../../..")
7-
set(EXAMPLE_DIR "${NODE_ADDON_API}/example")
8-
9-
file(GLOB_RECURSE SOURCES
10-
"${EXAMPLE_DIR}/*.cpp"
11-
"${EXAMPLE_DIR}/*.h"
12-
"${EXAMPLE_DIR}/basic_types/*.cpp"
13-
"${EXAMPLE_DIR}/dataview/*.cpp"
14-
"${EXAMPLE_DIR}/object/*.cpp"
15-
"${EXAMPLE_DIR}/threadsafe_function/*.cpp"
16-
"${EXAMPLE_DIR}/typed_threadsafe_function/*.cpp"
17-
)
186

197
if(DEFINED PACKAGE_FIND_FILE)
208
include(${PACKAGE_FIND_FILE})
@@ -23,6 +11,5 @@ endif()
2311
include_directories(${NATIVERENDER_ROOT_PATH}
2412
${NATIVERENDER_ROOT_PATH}/include)
2513

26-
add_library(entry SHARED ${SOURCES} napi_init.cpp)
27-
target_include_directories(entry PUBLIC ${NODE_ADDON_API})
28-
target_link_libraries(entry PUBLIC libace_napi.z.so)
14+
add_library(example SHARED ${SOURCES} napi_init.cpp)
15+
target_link_libraries(example PUBLIC libace_napi.z.so)
Original file line numberDiff line numberDiff line change
@@ -1,192 +1,53 @@
1-
#include "napi.h"
1+
#include "napi/native_api.h"
22

3-
using namespace Napi;
3+
static napi_value Add(napi_env env, napi_callback_info info)
4+
{
5+
size_t argc = 2;
6+
napi_value args[2] = {nullptr};
47

8+
napi_get_cb_info(env, info, &argc, args , nullptr, nullptr);
59

6-
#if (NAPI_VERSION > 5)
7-
Object InitAddon(Env env);
8-
Object InitAddonData(Env env);
9-
#endif
10-
Object InitArrayBuffer(Env env);
11-
Object InitAsyncContext(Env env);
12-
#if (NAPI_VERSION > 3)
13-
Object InitAsyncProgressQueueWorker(Env env);
14-
Object InitAsyncProgressWorker(Env env);
15-
#endif
16-
Object InitAsyncWorker(Env env);
17-
Object InitPersistentAsyncWorker(Env env);
18-
Object InitBasicTypesArray(Env env);
19-
Object InitBasicTypesBoolean(Env env);
20-
Object InitBasicTypesNumber(Env env);
21-
Object InitBasicTypesValue(Env env);
22-
#if (NAPI_VERSION > 5)
23-
Object InitBigInt(Env env);
24-
#endif
25-
Object InitBuffer(Env env);
26-
Object InitBufferNoExternal(Env env);
27-
#if (NAPI_VERSION > 2)
28-
Object InitCallbackScope(Env env);
29-
#endif
30-
#if (NAPI_VERSION > 4)
31-
Object InitDate(Env env);
32-
#endif
33-
Object InitCallbackInfo(Env env);
34-
Object InitDataView(Env env);
35-
Object InitDataViewReadWrite(Env env);
36-
Object InitEnvCleanup(Env env);
37-
Object InitErrorHandlingPrim(Env env);
38-
Object InitError(Env env);
39-
Object InitExternal(Env env);
40-
Object InitFunction(Env env);
41-
Object InitFunctionReference(Env env);
42-
Object InitHandleScope(Env env);
43-
Object InitMovableCallbacks(Env env);
44-
//Object InitMemoryManagement(Env env);
45-
Object InitName(Env env);
46-
Object InitObject(Env env);
47-
#ifndef NODE_ADDON_API_DISABLE_DEPRECATED
48-
Object InitObjectDeprecated(Env env);
49-
#endif // !NODE_ADDON_API_DISABLE_DEPRECATED
50-
Object InitPromise(Env env);
51-
//Object InitRunScript(Env env);
52-
#if (NAPI_VERSION > 3)
53-
Object InitThreadSafeFunctionCtx(Env env);
54-
Object InitThreadSafeFunctionException(Env env);
55-
Object InitThreadSafeFunctionExistingTsfn(Env env);
56-
Object InitThreadSafeFunctionPtr(Env env);
57-
Object InitThreadSafeFunctionSum(Env env);
58-
Object InitThreadSafeFunctionUnref(Env env);
59-
Object InitThreadSafeFunction(Env env);
60-
Object InitTypedThreadSafeFunctionCtx(Env env);
61-
Object InitTypedThreadSafeFunctionException(Env env);
62-
Object InitTypedThreadSafeFunctionExistingTsfn(Env env);
63-
Object InitTypedThreadSafeFunctionPtr(Env env);
64-
Object InitTypedThreadSafeFunctionSum(Env env);
65-
Object InitTypedThreadSafeFunctionUnref(Env env);
66-
Object InitTypedThreadSafeFunction(Env env);
67-
#endif
68-
//Object InitSymbol(Env env);
69-
Object InitTypedArray(Env env);
70-
//Object InitGlobalObject(Env env);
71-
Object InitObjectWrap(Env env);
72-
Object InitObjectWrapConstructorException(Env env);
73-
Object InitObjectWrapFunction(Env env);
74-
Object InitObjectWrapRemoveWrap(Env env);
75-
Object InitObjectWrapMultipleInheritance(Env env);
76-
Object InitObjectReference(Env env);
77-
Object InitReference(Env env);
78-
Object InitVersionManagement(Env env);
79-
Object InitThunkingManual(Env env);
80-
#if (NAPI_VERSION > 7)
81-
Object InitObjectFreezeSeal(Env env);
82-
Object InitTypeTaggable(Env env);
83-
#endif
84-
#if (NAPI_VERSION > 8)
85-
Object InitEnvMiscellaneous(Env env);
86-
#endif
87-
#if defined(NODE_ADDON_API_ENABLE_MAYBE)
88-
Object InitMaybeCheck(Env env);
89-
#endif
10+
napi_valuetype valuetype0;
11+
napi_typeof(env, args[0], &valuetype0);
9012

91-
Object EntryInit(Env env, Object exports) {
92-
#if (NAPI_VERSION > 5)
93-
exports.Set("addon", InitAddon(env));
94-
exports.Set("addon_data", InitAddonData(env));
95-
#endif
96-
exports.Set("arraybuffer", InitArrayBuffer(env));
97-
exports.Set("asynccontext", InitAsyncContext(env));
98-
#if (NAPI_VERSION > 3)
99-
exports.Set("asyncprogressqueueworker", InitAsyncProgressQueueWorker(env));
100-
exports.Set("asyncprogressworker", InitAsyncProgressWorker(env));
101-
#endif
102-
// exports.Set("globalObject", InitGlobalObject(env));
103-
exports.Set("asyncworker", InitAsyncWorker(env));
104-
exports.Set("persistentasyncworker", InitPersistentAsyncWorker(env));
105-
exports.Set("basic_types_array", InitBasicTypesArray(env));
106-
exports.Set("basic_types_boolean", InitBasicTypesBoolean(env));
107-
exports.Set("basic_types_number", InitBasicTypesNumber(env));
108-
exports.Set("basic_types_value", InitBasicTypesValue(env));
109-
#if (NAPI_VERSION > 5)
110-
exports.Set("bigint", InitBigInt(env));
111-
#endif
112-
#if (NAPI_VERSION > 4)
113-
exports.Set("date", InitDate(env));
114-
#endif
115-
exports.Set("buffer", InitBuffer(env));
116-
exports.Set("bufferNoExternal", InitBufferNoExternal(env));
117-
#if (NAPI_VERSION > 2)
118-
exports.Set("callbackscope", InitCallbackScope(env));
119-
#endif
120-
exports.Set("callbackInfo", InitCallbackInfo(env));
121-
exports.Set("dataview", InitDataView(env));
122-
exports.Set("dataview_read_write", InitDataView(env));
123-
exports.Set("dataview_read_write", InitDataViewReadWrite(env));
124-
#if (NAPI_VERSION > 2)
125-
exports.Set("env_cleanup", InitEnvCleanup(env));
126-
#endif
127-
exports.Set("error", InitError(env));
128-
exports.Set("errorHandlingPrim", InitErrorHandlingPrim(env));
129-
exports.Set("external", InitExternal(env));
130-
exports.Set("function", InitFunction(env));
131-
exports.Set("functionreference", InitFunctionReference(env));
132-
exports.Set("name", InitName(env));
133-
exports.Set("handlescope", InitHandleScope(env));
134-
exports.Set("movable_callbacks", InitMovableCallbacks(env));
135-
// exports.Set("memory_management", InitMemoryManagement(env));
136-
exports.Set("object", InitObject(env));
137-
#ifndef NODE_ADDON_API_DISABLE_DEPRECATED
138-
exports.Set("object_deprecated", InitObjectDeprecated(env));
139-
#endif // !NODE_ADDON_API_DISABLE_DEPRECATED
140-
exports.Set("promise", InitPromise(env));
141-
// exports.Set("symbol", InitSymbol(env));
142-
#if (NAPI_VERSION > 3)
143-
exports.Set("threadsafe_function_ctx", InitThreadSafeFunctionCtx(env));
144-
exports.Set("threadsafe_function_exception",
145-
InitThreadSafeFunctionException(env));
146-
exports.Set("threadsafe_function_existing_tsfn",
147-
InitThreadSafeFunctionExistingTsfn(env));
148-
exports.Set("threadsafe_function_ptr", InitThreadSafeFunctionPtr(env));
149-
exports.Set("threadsafe_function_sum", InitThreadSafeFunctionSum(env));
150-
exports.Set("threadsafe_function_unref", InitThreadSafeFunctionUnref(env));
151-
exports.Set("threadsafe_function", InitThreadSafeFunction(env));
152-
exports.Set("typed_threadsafe_function_ctx",
153-
InitTypedThreadSafeFunctionCtx(env));
154-
exports.Set("typed_threadsafe_function_exception",
155-
InitTypedThreadSafeFunctionException(env));
156-
exports.Set("typed_threadsafe_function_existing_tsfn",
157-
InitTypedThreadSafeFunctionExistingTsfn(env));
158-
exports.Set("typed_threadsafe_function_ptr",
159-
InitTypedThreadSafeFunctionPtr(env));
160-
exports.Set("typed_threadsafe_function_sum",
161-
InitTypedThreadSafeFunctionSum(env));
162-
exports.Set("typed_threadsafe_function_unref",
163-
InitTypedThreadSafeFunctionUnref(env));
164-
exports.Set("typed_threadsafe_function", InitTypedThreadSafeFunction(env));
165-
#endif
166-
exports.Set("typedarray", InitTypedArray(env));
167-
exports.Set("objectwrap", InitObjectWrap(env));
168-
exports.Set("objectwrapConstructorException",
169-
InitObjectWrapConstructorException(env));
170-
exports.Set("objectwrap_function", InitObjectWrapFunction(env));
171-
exports.Set("objectwrap_removewrap", InitObjectWrapRemoveWrap(env));
172-
exports.Set("objectwrap_multiple_inheritance",
173-
InitObjectWrapMultipleInheritance(env));
174-
exports.Set("objectreference", InitObjectReference(env));
175-
exports.Set("reference", InitReference(env));
176-
exports.Set("version_management", InitVersionManagement(env));
177-
exports.Set("thunking_manual", InitThunkingManual(env));
178-
#if (NAPI_VERSION > 7)
179-
exports.Set("object_freeze_seal", InitObjectFreezeSeal(env));
180-
exports.Set("type_taggable", InitTypeTaggable(env));
181-
#endif
182-
#if (NAPI_VERSION > 8)
183-
exports.Set("env_misc", InitEnvMiscellaneous(env));
184-
#endif
13+
napi_valuetype valuetype1;
14+
napi_typeof(env, args[1], &valuetype1);
18515

186-
#if defined(NODE_ADDON_API_ENABLE_MAYBE)
187-
exports.Set("maybe_check", InitMaybeCheck(env));
188-
#endif
16+
double value0;
17+
napi_get_value_double(env, args[0], &value0);
18+
19+
double value1;
20+
napi_get_value_double(env, args[1], &value1);
21+
22+
napi_value sum;
23+
napi_create_double(env, value0 + value1, &sum);
24+
25+
return sum;
26+
27+
}
28+
29+
EXTERN_C_START
30+
static napi_value Init(napi_env env, napi_value exports)
31+
{
32+
napi_property_descriptor desc[] = {
33+
{ "add", nullptr, Add, nullptr, nullptr, nullptr, napi_default, nullptr }
34+
};
35+
napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc);
18936
return exports;
19037
}
38+
EXTERN_C_END
19139

192-
NODE_API_MODULE(entry, EntryInit)
40+
static napi_module demoModule = {
41+
.nm_version = 1,
42+
.nm_flags = 0,
43+
.nm_filename = nullptr,
44+
.nm_register_func = Init,
45+
.nm_modname = "entry",
46+
.nm_priv = ((void*)0),
47+
.reserved = { 0 },
48+
};
49+
50+
extern "C" __attribute__((constructor)) void RegisterEntryModule(void)
51+
{
52+
napi_module_register(&demoModule);
53+
}

ohos_addon_example/entry/src/main/cpp/types/libentry/Index.d.ts

-16
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export {}

ohos_addon_example/entry/src/main/cpp/types/libentry/oh-package.json5 renamed to ohos_addon_example/entry/src/main/cpp/types/libexample/oh-package.json5

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "libentry.so",
2+
"name": "libexmaple.so",
33
"types": "./Index.d.ts",
44
"version": "1.0.0",
55
"description": "Please describe the basic information."

ohos_addon_example/entry/src/main/ets/pages/Index.ets

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { hilog } from '@kit.PerformanceAnalysisKit';
2-
import * as testNapi from 'libentry.so';
32

43
@Entry
54
@Component
@@ -13,9 +12,7 @@ struct Index {
1312
.fontSize(50)
1413
.fontWeight(FontWeight.Bold)
1514
.onClick(() => {
16-
const a = testNapi;
17-
const ret = testNapi.basic_types_boolean.createBoolean(false);
18-
console.log(`${ret}`);
15+
hilog.debug(0x0000,"","");
1916
})
2017
}
2118
.width('100%')

ohos_addon_example/entry/src/ohosTest/ets/test/Ability.test.ets

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { hilog } from '@kit.PerformanceAnalysisKit';
2-
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium';
2+
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from './util/framework.test';
33

44
export default function abilityTest() {
55
describe('ActsAbilityTest', () => {

ohos_addon_example/entry/src/ohosTest/ets/test/BasicTypes/Array.test.ets renamed to ohos_addon_example/entry/src/ohosTest/ets/test/BasicTypes/Array.test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { describe, expect, it, DEFAULT } from '@ohos/hypium';
2-
import testNapi, {basic_types_array} from 'libentry.so';
1+
import { describe, expect, it, DEFAULT } from '../util/framework.test';
2+
import binding from '../util/binding';
33

44
export default function basicTypeArray() {
55
describe("basic_type_array_test", () => {
66
it("RunArray", DEFAULT, () => {
7-
const basic_types_array: basic_types_array = testNapi.basic_types_array;
7+
const basic_types_array: ESObject = binding.basic_types_array;
88

99
const array = basic_types_array.createArray();
1010
expect(basic_types_array.getLength(array)).assertEqual(0);

ohos_addon_example/entry/src/ohosTest/ets/test/BasicTypes/Boolean.test.ets renamed to ohos_addon_example/entry/src/ohosTest/ets/test/BasicTypes/Boolean.test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { describe, expect, it, DEFAULT } from '@ohos/hypium';
2-
import testNapi, { basic_types_boolean } from 'libentry.so';
1+
import { describe, expect, it, DEFAULT } from '../util/framework.test';
2+
import binding from '../util/binding';
33

44
export default function basicTypeBoolean() {
55
describe("basic_type_boolean_test", () => {
66
it("RunBoolean", DEFAULT, () => {
7-
const basic_types_boolean: basic_types_boolean = testNapi.basic_types_boolean;
7+
const basic_types_boolean: ESObject = binding.basic_types_boolean;
88

99
expect(basic_types_boolean.createBoolean(true)).assertTrue();
1010
expect(basic_types_boolean.createBoolean(false)).assertFalse();

0 commit comments

Comments
 (0)