diff --git a/arkcompiler/esmodule/esmodule_entry/entry/src/main/ets/test/DynamicImport.ets b/arkcompiler/esmodule/esmodule_entry/entry/src/main/ets/test/DynamicImport.ets new file mode 100644 index 0000000000000000000000000000000000000000..4eadb21a43f0aa8b50b90a44795863538b62cb06 --- /dev/null +++ b/arkcompiler/esmodule/esmodule_entry/entry/src/main/ets/test/DynamicImport.ets @@ -0,0 +1,45 @@ +/** + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import {describe, it, expect} from "@ohos/hypium" + +export default function dynamicImport() { + describe("DynamicImportTest", async () => { + it('importHar', 0, async () => { + let lib = await import('har') + expect(lib.add(2, 3)).assertEqual(5) + }) + it('importRelative', 0, async () => { + let lib = await import('./test') + expect(lib.add(2, 3)).assertEqual(5) + expect(lib.default).assertEqual('test') + }) + it('importOhpm', 0, async () => { + let lib = await import('leap-year') + expect(lib.default(2000)).assertEqual(true) + }) + it('importSystemInternal', 0, async () => { + let lib = await import('@ohos.hilog') + lib.default.info(0x0000, "testTag", 'dexter log: call ohos.hilog') + }) + it('importSystemBuiltin', 0, async () => { + let lib = await import('@system.app') + lib.default.getInfo() + }) + it('importAppNapi', 0, async () => { + let lib = await import('libentry.so') + expect(lib.default.add(2,3)).assertEqual(5) + }) + }) +} \ No newline at end of file diff --git a/arkcompiler/esmodule/esmodule_entry/entry/src/main/ets/test/List.test.ets b/arkcompiler/esmodule/esmodule_entry/entry/src/main/ets/test/List.test.ets index b4043934273859167cdd349070d687c88d500154..71be06b51d82e2558f94de6dc27340a56c0aed27 100644 --- a/arkcompiler/esmodule/esmodule_entry/entry/src/main/ets/test/List.test.ets +++ b/arkcompiler/esmodule/esmodule_entry/entry/src/main/ets/test/List.test.ets @@ -13,11 +13,13 @@ * limitations under the License. */ import staticImport from './StaticImport' +import dynamicImport from './DynamicImport' import workerImport from "./WorkerImport" import pageImport from './PageImport' export default function testsuite() { staticImport() + dynamicImport() workerImport() pageImport() } \ No newline at end of file diff --git a/arkcompiler/esmodule/esmodule_ohostest/entry/oh-package.json5 b/arkcompiler/esmodule/esmodule_ohostest/entry/oh-package.json5 index b0766130e7ea63f6a61100b416a7d04db25f37fd..04d2f1556358d856d64cbe77a71110d3437d49ae 100644 --- a/arkcompiler/esmodule/esmodule_ohostest/entry/oh-package.json5 +++ b/arkcompiler/esmodule/esmodule_ohostest/entry/oh-package.json5 @@ -14,7 +14,9 @@ */ { "license": "", - "devDependencies": {}, + "devDependencies": { + "@types/libentry.so": "file:./src/ohosTest/cpp/types/libentry" + }, "author": "", "name": "entry", "description": "Please describe the basic information.", @@ -23,4 +25,4 @@ "dependencies": { "har": "file:../har" } -} +} \ No newline at end of file diff --git a/arkcompiler/esmodule/esmodule_ohostest/entry/src/ohosTest/cpp/CMakeLists.txt b/arkcompiler/esmodule/esmodule_ohostest/entry/src/ohosTest/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..1f76883a9027bf797a4090223d90b78f28b4b8c3 --- /dev/null +++ b/arkcompiler/esmodule/esmodule_ohostest/entry/src/ohosTest/cpp/CMakeLists.txt @@ -0,0 +1,11 @@ +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.4.1) +project(MyApplication8) + +set(NATIVERENDER_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}) + +include_directories(${NATIVERENDER_ROOT_PATH} + ${NATIVERENDER_ROOT_PATH}/include) + +add_library(entry SHARED hello.cpp) +target_link_libraries(entry PUBLIC libace_napi.z.so) \ No newline at end of file diff --git a/arkcompiler/esmodule/esmodule_ohostest/entry/src/ohosTest/cpp/hello.cpp b/arkcompiler/esmodule/esmodule_ohostest/entry/src/ohosTest/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3eb38b21de56a7853c7751ca4a83480ced262edd --- /dev/null +++ b/arkcompiler/esmodule/esmodule_ohostest/entry/src/ohosTest/cpp/hello.cpp @@ -0,0 +1,67 @@ +/** + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "napi/native_api.h" + +static napi_value Add(napi_env env, napi_callback_info info) +{ + size_t requireArgc = 2; + size_t argc = 2; + napi_value args[2] = {nullptr}; + + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + napi_valuetype valuetype0; + napi_typeof(env, args[0], &valuetype0); + + napi_valuetype valuetype1; + napi_typeof(env, args[1], &valuetype1); + + 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 + +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); +} diff --git a/arkcompiler/esmodule/esmodule_ohostest/entry/src/ohosTest/cpp/types/libentry/index.d.ts b/arkcompiler/esmodule/esmodule_ohostest/entry/src/ohosTest/cpp/types/libentry/index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..24b396c9d80d67fe63ee749eb840b2f8d05b7836 --- /dev/null +++ b/arkcompiler/esmodule/esmodule_ohostest/entry/src/ohosTest/cpp/types/libentry/index.d.ts @@ -0,0 +1,15 @@ +/** + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +export const add: (a: number, b: number) => number; \ No newline at end of file diff --git a/arkcompiler/esmodule/esmodule_ohostest/entry/src/ohosTest/cpp/types/libentry/oh-package.json5 b/arkcompiler/esmodule/esmodule_ohostest/entry/src/ohosTest/cpp/types/libentry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..482d89e7ee789b004b0aee2d8b3092981b6d5e6d --- /dev/null +++ b/arkcompiler/esmodule/esmodule_ohostest/entry/src/ohosTest/cpp/types/libentry/oh-package.json5 @@ -0,0 +1,20 @@ +/** + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "name": "libentry.so", + "types": "./index.d.ts", + "version": "", + "description": "Please describe the basic information." +} \ No newline at end of file