未验证 提交 adc54128 编写于 作者: O openharmony_ci 提交者: Gitee

!9933 ArkTs整改挑单monthly分支

Merge pull request !9933 from huyunhui/cherry-pick-1693280731
/**
* 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
...@@ -13,11 +13,13 @@ ...@@ -13,11 +13,13 @@
* limitations under the License. * limitations under the License.
*/ */
import staticImport from './StaticImport' import staticImport from './StaticImport'
import dynamicImport from './DynamicImport'
import workerImport from "./WorkerImport" import workerImport from "./WorkerImport"
import pageImport from './PageImport' import pageImport from './PageImport'
export default function testsuite() { export default function testsuite() {
staticImport() staticImport()
dynamicImport()
workerImport() workerImport()
pageImport() pageImport()
} }
\ No newline at end of file
...@@ -14,7 +14,9 @@ ...@@ -14,7 +14,9 @@
*/ */
{ {
"license": "", "license": "",
"devDependencies": {}, "devDependencies": {
"@types/libentry.so": "file:./src/ohosTest/cpp/types/libentry"
},
"author": "", "author": "",
"name": "entry", "name": "entry",
"description": "Please describe the basic information.", "description": "Please describe the basic information.",
...@@ -23,4 +25,4 @@ ...@@ -23,4 +25,4 @@
"dependencies": { "dependencies": {
"har": "file:../har" "har": "file:../har"
} }
} }
\ No newline at end of file
# 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
/**
* 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);
}
/**
* 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
/**
* 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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册