提交 6f2f82fc 编写于 作者: 耿文广

新增包管理native接口工程模板

Signed-off-by: N耿文广 <gengwenguang@huawei.com>
上级 eb83435d
......@@ -28,7 +28,7 @@ group("bundlemanager") {
"actsbmsstageetstest:ActBmsStageEtsTest",
"actsbundlemanageretstest:ActsBundleManagerEtsTest",
"actsbundlemanagertest:ActsBundleManagerTest",
"actsbundlenativetest:ActsBmsNapiEtsTest",
"actsbundlenativetest:ActsBundleNativeTest",
"sceneProject/bmsaccesstokenfive:bmsAccessTokenTest5",
"sceneProject/bmsaccesstokenfour:bmsAccessTokenTest4",
"sceneProject/bmsaccesstokenone:bmsAccessTokenTest1",
......
# Copyright (c) 2021 Huawei Device Co., Ltd.
# Copyright (c) 2022 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
......@@ -13,7 +13,7 @@
import("//build/ohos.gni")
import("//test/xts/tools/build/suite.gni")
ohos_js_hap_suite("ActsBmsNapiEtsTest") {
ohos_js_hap_suite("ActsBundleNativeTest") {
hap_profile = "./entry/src/main/config.json"
deps = [
":ace_third_ets_assets",
......@@ -22,8 +22,20 @@ ohos_js_hap_suite("ActsBmsNapiEtsTest") {
]
ets2abc = true
certificate_profile = "./signature/openharmony_sx.p7b"
hap_name = "ActsBmsNapiEtsTest"
shared_libraries = [ "./entry/src/main/cpp:teststring" ]
hap_name = "ActsBundleNativeTest"
shared_libraries = [ "./entry/src/main/cpp:bundlendk" ]
}
ohos_prebuilt_shared_library("libcppsharedso") {
if (!(product_name == "m40")) {
if (target_cpu == "arm") {
source = "//prebuilts/clang/ohos/linux-x86_64/libcxx-ndk/lib/arm-linux-ohos/c++/libc++_shared.so"
} else if (target_cpu == "arm64") {
source = "//prebuilts/clang/ohos/linux-x86_64/libcxx-ndk/lib/aarch64-linux-ohos/c++/libc++_shared.so"
} else {
source = " "
}
}
}
ohos_js_assets("ace_third_ets_assets") {
......
......@@ -3,14 +3,14 @@
"driver": {
"type": "OHJSUnitTest",
"test-timeout": "600000",
"bundle-name": "com.example.nativetest",
"package-name": "com.example.nativetest",
"bundle-name": "com.actsbundle.napitest",
"package-name": "com.actsbundle.napitest",
"shell-timeout": "600000"
},
"kits": [
{
"test-file-name": [
"ActsBmsNapiEtsTest.hap"
"ActsBundleNativeTest.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
......
{
"app": {
"bundleName": "com.example.nativetest",
"vendor": "example",
"bundleName": "com.actsbundle.napitest",
"vendor": "open",
"version": {
"code": 1000000,
"name": "1.0.0"
......@@ -14,9 +14,9 @@
},
"deviceConfig": {},
"module": {
"package": "com.example.nativetest",
"package": "com.actsbundle.napitest",
"name": ".MyApplication",
"mainAbility": "com.example.nativetest.MainAbility",
"mainAbility": "com.actsbundle.napitest.MainAbility",
"deviceType": [
"phone"
......
# Copyright (C) 2021 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("//build/config/ohos/config.gni")
import("//build/ohos.gni")
import("//foundation/arkui/napi/napi.gni")
config("config") {
visibility = [ ":*" ]
cflags = [
"-Wall",
"-Werror",
"-g3",
"-Wunused-variable",
]
}
config("public_config") {
}
ohos_shared_library("teststring") {
sources = [ "./teststring.cpp" ]
if (!(product_name == "m40")) {
if (target_cpu == "arm") {
libs = [ "${clang_base_path}/../libcxx-ndk/lib/arm-linux-ohos/c++/libc++_shared.so" ]
} else if (target_cpu == "arm64") {
libs = [ "${clang_base_path}/../libcxx-ndk/lib/aarch64-linux-ohos/c++/libc++_shared.so" ]
} else {
libs = []
}
}
include_dirs = [ "//test/xts/acts/arkui/ace_napi_test/entry/src/main/cpp" ]
configs = [ ":config" ]
deps = [ "//foundation/arkui/napi:ace_napi" ]
output_extension = "so"
}
# Copyright (C) 2022 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("//build/config/ohos/config.gni")
import("//build/ohos.gni")
config("config") {
visibility = [ ":*" ]
cflags = [
"-Wall",
"-Werror",
"-g3",
"-Wunused-variable",
]
}
config("public_config") {
}
ohos_shared_library("bundlendk") {
sources = [ "./bundlendk.cpp" ]
if (!(product_name == "m40")) {
if (target_cpu == "arm") {
libs = [ "${clang_base_path}/../libcxx-ndk/lib/arm-linux-ohos/c++/libc++_shared.so" ]
} else if (target_cpu == "arm64") {
libs = [ "${clang_base_path}/../libcxx-ndk/lib/aarch64-linux-ohos/c++/libc++_shared.so" ]
} else {
libs = []
}
}
include_dirs = [ "//test/xts/acts/bundlemanager/bundle_standard/bundlemanager/actsbundlenativetest/entry/src/main/cpp" ]
configs = [ ":config" ]
deps = [
"//foundation/arkui/napi:ace_napi",
"//foundation/bundlemanager/bundle_framework/interfaces/kits/native/bundle:bundle_ndk",
]
output_extension = "so"
}
# the minimum version of CMake.
cmake_minimum_required(VERSION 3.4.1)
project(XComponent)
set(NATIVERENDER_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR})
include_directories(${NATIVERENDER_ROOT_PATH}
${NATIVERENDER_ROOT_PATH}/include)
add_library(teststring SHARED teststring.cpp)
target_link_libraries(teststring PUBLIC libace_nap i.z.so libc++.a)
\ No newline at end of file
# the minimum version of CMake.
cmake_minimum_required(VERSION 3.4.1)
project(XComponent)
set(NATIVERENDER_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR})
include_directories(${NATIVERENDER_ROOT_PATH}
${NATIVERENDER_ROOT_PATH}/include)
add_library(bundlendk SHARED bundlendk.cpp)
target_link_libraries(bundlendk PUBLIC libace_napi.z.so libc++.a libbundle_ndk.z.so )
\ No newline at end of file
/*
* Copyright (c) 2022 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"
#include "native_interface_bundle.h"
#include <cstdlib>
#include <js_native_api_types.h>
static napi_value GetCurrentApplicationInfo(napi_env env, napi_callback_info info)
{
OH_NativeBundle_ApplicationInfo nativeApplicationInfo = OH_NativeBundle_GetCurrentApplicationInfo();
napi_value result = nullptr;
napi_create_object(env, &result);
napi_value bundleName;
napi_create_string_utf8(env, nativeApplicationInfo.bundleName, NAPI_AUTO_LENGTH, &bundleName);
napi_set_named_property(env, result, "bundleName", bundleName);
napi_value fingerprint;
napi_create_string_utf8(env, nativeApplicationInfo.fingerprint, NAPI_AUTO_LENGTH, &fingerprint);
napi_set_named_property(env, result, "fingerprint", fingerprint);
return result;
}
EXTERN_C_START
static napi_value Init(napi_env env, napi_value exports)
{
napi_property_descriptor desc[] = {
{ "getCurrentApplicationInfo", nullptr, GetCurrentApplicationInfo,
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 = "libbundlendk",
.nm_priv = ((void*)0),
.reserved = { 0 },
};
extern "C" __attribute__((constructor)) void RegisterModule(void)
{
napi_module_register(&demoModule);
}
#include "napi/native_api.h"
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);
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 = "libhello",
.nm_priv = ((void*)0),
.reserved = { 0 },
};
extern "C" __attribute__((constructor)) void RegisterHelloModule(void)
{
napi_module_register(&demoModule);
}
export const add: (a: number, b: number) => number;
\ No newline at end of file
export const GetCurrentApplicationInfo: () => object;
\ No newline at end of file
{
"name": "libteststring.so",
"types": "./index.d.ts"
"name": "libbundlendk.so",
"types": "./index.d.ts"
}
\ No newline at end of file
// @ts-nocheck
/**
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2022 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
......
// @ts-nocheck
/**
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2022 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
......@@ -26,7 +25,7 @@ struct MyComponent {
alignItems: ItemAlign.Center,
justifyContent: FlexAlign.Center
}) {
Text('ACE ETS TEST')
Text('BMS ETS TEST')
.fontSize(50)
.fontWeight(FontWeight.Bold)
}
......
// @ts-nocheck
/**
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2022 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
......
// @ts-nocheck
/**
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2022 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
......
// @ts-nocheck
/**
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2022 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
......
// @ts-nocheck
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2022 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
......@@ -15,43 +14,26 @@
*/
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from "hypium/index"
import testString from 'libteststring.so'
export default function nativeApiStringJsunit() {
describe('napiStringTest', function () {
const empty = '';
var value;
async function sleep(time) {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve()
}, time)
}).then(() => {
console.info( `sleep ${time} over...`)
})
}
/**
* run after testcase
*/
afterEach(async function () {
console.info('[napiStringTest] after each called')
value == '';
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0100
* @tc.name napiStringTest001
* @tc.desc aceNapiEtsTest
*/
it('napiStringTest001', 0, async function (done) {
console.info("Test NAPI 2 + 3 = " + testString.Add(2, 3));
done();
});
})
import bundlendk from 'libbundlendk.so'
const BUNDLE_NAME = "com.actsbundle.napitest"
const FINGER_PRINT = "7B3D8586460A7666621992FD367993D7ECDE40A8FD8E9CF525A48822E9A62655"
export default function budnleNdkNativeTest() {
describe('BundleNdkTest', function () {
/**
* @tc.number SUB_BMS_BASIC_ETS_NATIVE_0100
* @tc.name budnleNdkNativeTest001
* @tc.desc budnleNdkNativeTest
*/
it('BundleNdkTest001', 0, async function (done) {
let data = bundlendk.getCurrentApplicationInfo();
console.info("Test NAPI data= " + JSON.stringify(data));
expect(data.bundleName).assertEqual(BUNDLE_NAME);
expect(data.fingerprint).assertEqual(FINGER_PRINT);
done()
});
})
}
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2022 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
......@@ -12,8 +12,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import napiStringTest from './NativeApiStringTest';
import budnleNdkNativeTest from './BudnleNdkNativeTest';
export default function testsuite() {
napiStringTest()
budnleNdkNativeTest()
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册