From 580e2ecfda81737c3d2ae5b2b67ceb9ee4eed137 Mon Sep 17 00:00:00 2001 From: "OWNEROR-41FNVD0\\lenovo" Date: Sat, 24 May 2025 16:07:55 +0800 Subject: [PATCH] =?UTF-8?q?RationalUseOfFrontEndResources=E5=B7=A5?= =?UTF-8?q?=E7=A8=8B=E6=8A=A5=E9=94=99=E8=A7=A3=E5=86=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entry/src/main/cpp/CMakeLists.txt | 15 ++++++ .../entry/src/main/cpp/napi_init.cpp | 53 +++++++++++++++++++ .../src/main/cpp/types/libentry/index.d.ts | 1 + .../main/cpp/types/libentry/oh-package.json5 | 6 +++ .../entry/src/main/ets/pages/Index.ets | 23 ++++++++ .../resources/base/profile/main_pages.json | 1 + .../entry/src/mock/mock-config.json5 | 2 - .../src/ohosTest/ets/test/Ability.test.ets | 35 ------------ .../entry/src/ohosTest/ets/test/List.test.ets | 5 -- .../entry/src/ohosTest/module.json5 | 13 ----- .../entry/src/test/List.test.ets | 5 -- .../entry/src/test/LocalUnit.test.ets | 33 ------------ 12 files changed, 99 insertions(+), 93 deletions(-) create mode 100644 RationalUseOfFrontEndResources/entry/src/main/cpp/CMakeLists.txt create mode 100644 RationalUseOfFrontEndResources/entry/src/main/cpp/napi_init.cpp create mode 100644 RationalUseOfFrontEndResources/entry/src/main/cpp/types/libentry/index.d.ts create mode 100644 RationalUseOfFrontEndResources/entry/src/main/cpp/types/libentry/oh-package.json5 create mode 100644 RationalUseOfFrontEndResources/entry/src/main/ets/pages/Index.ets delete mode 100644 RationalUseOfFrontEndResources/entry/src/mock/mock-config.json5 delete mode 100644 RationalUseOfFrontEndResources/entry/src/ohosTest/ets/test/Ability.test.ets delete mode 100644 RationalUseOfFrontEndResources/entry/src/ohosTest/ets/test/List.test.ets delete mode 100644 RationalUseOfFrontEndResources/entry/src/ohosTest/module.json5 delete mode 100644 RationalUseOfFrontEndResources/entry/src/test/List.test.ets delete mode 100644 RationalUseOfFrontEndResources/entry/src/test/LocalUnit.test.ets diff --git a/RationalUseOfFrontEndResources/entry/src/main/cpp/CMakeLists.txt b/RationalUseOfFrontEndResources/entry/src/main/cpp/CMakeLists.txt new file mode 100644 index 00000000..1acd3ec1 --- /dev/null +++ b/RationalUseOfFrontEndResources/entry/src/main/cpp/CMakeLists.txt @@ -0,0 +1,15 @@ +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.5.0) +project(CppCrash) + +set(NATIVERENDER_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}) + +if(DEFINED PACKAGE_FIND_FILE) + include(${PACKAGE_FIND_FILE}) +endif() + +include_directories(${NATIVERENDER_ROOT_PATH} + ${NATIVERENDER_ROOT_PATH}/include) + +add_library(entry SHARED napi_init.cpp) +target_link_libraries(entry PUBLIC libace_napi.z.so) \ No newline at end of file diff --git a/RationalUseOfFrontEndResources/entry/src/main/cpp/napi_init.cpp b/RationalUseOfFrontEndResources/entry/src/main/cpp/napi_init.cpp new file mode 100644 index 00000000..85330e3e --- /dev/null +++ b/RationalUseOfFrontEndResources/entry/src/main/cpp/napi_init.cpp @@ -0,0 +1,53 @@ +#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 = "entry", + .nm_priv = ((void*)0), + .reserved = { 0 }, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) +{ + napi_module_register(&demoModule); +} diff --git a/RationalUseOfFrontEndResources/entry/src/main/cpp/types/libentry/index.d.ts b/RationalUseOfFrontEndResources/entry/src/main/cpp/types/libentry/index.d.ts new file mode 100644 index 00000000..e44f3615 --- /dev/null +++ b/RationalUseOfFrontEndResources/entry/src/main/cpp/types/libentry/index.d.ts @@ -0,0 +1 @@ +export const add: (a: number, b: number) => number; \ No newline at end of file diff --git a/RationalUseOfFrontEndResources/entry/src/main/cpp/types/libentry/oh-package.json5 b/RationalUseOfFrontEndResources/entry/src/main/cpp/types/libentry/oh-package.json5 new file mode 100644 index 00000000..17f2fec2 --- /dev/null +++ b/RationalUseOfFrontEndResources/entry/src/main/cpp/types/libentry/oh-package.json5 @@ -0,0 +1,6 @@ +{ + "name": "libentry.so", + "types": "./index.d.ts", + "version": "1.0.0", + "description": "Please describe the basic information." +} \ No newline at end of file diff --git a/RationalUseOfFrontEndResources/entry/src/main/ets/pages/Index.ets b/RationalUseOfFrontEndResources/entry/src/main/ets/pages/Index.ets new file mode 100644 index 00000000..8e2d24ad --- /dev/null +++ b/RationalUseOfFrontEndResources/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,23 @@ +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + RelativeContainer() { + Text(this.message) + .id('HelloWorld') + .fontSize($r('app.float.page_text_font_size')) + .fontWeight(FontWeight.Bold) + .alignRules({ + center: { anchor: '__container__', align: VerticalAlign.Center }, + middle: { anchor: '__container__', align: HorizontalAlign.Center } + }) + .onClick(() => { + this.message = 'Welcome'; + }) + } + .height('100%') + .width('100%') + } +} \ No newline at end of file diff --git a/RationalUseOfFrontEndResources/entry/src/main/resources/base/profile/main_pages.json b/RationalUseOfFrontEndResources/entry/src/main/resources/base/profile/main_pages.json index 1612af3c..1898d94f 100644 --- a/RationalUseOfFrontEndResources/entry/src/main/resources/base/profile/main_pages.json +++ b/RationalUseOfFrontEndResources/entry/src/main/resources/base/profile/main_pages.json @@ -1,4 +1,5 @@ { "src": [ + "pages/Index" ] } diff --git a/RationalUseOfFrontEndResources/entry/src/mock/mock-config.json5 b/RationalUseOfFrontEndResources/entry/src/mock/mock-config.json5 deleted file mode 100644 index 7a73a41b..00000000 --- a/RationalUseOfFrontEndResources/entry/src/mock/mock-config.json5 +++ /dev/null @@ -1,2 +0,0 @@ -{ -} \ No newline at end of file diff --git a/RationalUseOfFrontEndResources/entry/src/ohosTest/ets/test/Ability.test.ets b/RationalUseOfFrontEndResources/entry/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100644 index 85c78f67..00000000 --- a/RationalUseOfFrontEndResources/entry/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,35 +0,0 @@ -import { hilog } from '@kit.PerformanceAnalysisKit'; -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; - -export default function abilityTest() { - describe('ActsAbilityTest', () => { - // Defines a test suite. Two parameters are supported: test suite name and test suite function. - beforeAll(() => { - // Presets an action, which is performed only once before all test cases of the test suite start. - // This API supports only one parameter: preset action function. - }) - beforeEach(() => { - // Presets an action, which is performed before each unit test case starts. - // The number of execution times is the same as the number of test cases defined by **it**. - // This API supports only one parameter: preset action function. - }) - afterEach(() => { - // Presets a clear action, which is performed after each unit test case ends. - // The number of execution times is the same as the number of test cases defined by **it**. - // This API supports only one parameter: clear action function. - }) - afterAll(() => { - // Presets a clear action, which is performed after all test cases of the test suite end. - // This API supports only one parameter: clear action function. - }) - it('assertContain', 0, () => { - // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. - hilog.info(0x0000, 'testTag', '%{public}s', 'it begin'); - let a = 'abc'; - let b = 'b'; - // Defines a variety of assertion methods, which are used to declare expected boolean conditions. - expect(a).assertContain(b); - expect(a).assertEqual(a); - }) - }) -} \ No newline at end of file diff --git a/RationalUseOfFrontEndResources/entry/src/ohosTest/ets/test/List.test.ets b/RationalUseOfFrontEndResources/entry/src/ohosTest/ets/test/List.test.ets deleted file mode 100644 index 794c7dc4..00000000 --- a/RationalUseOfFrontEndResources/entry/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,5 +0,0 @@ -import abilityTest from './Ability.test'; - -export default function testsuite() { - abilityTest(); -} \ No newline at end of file diff --git a/RationalUseOfFrontEndResources/entry/src/ohosTest/module.json5 b/RationalUseOfFrontEndResources/entry/src/ohosTest/module.json5 deleted file mode 100644 index 55725a92..00000000 --- a/RationalUseOfFrontEndResources/entry/src/ohosTest/module.json5 +++ /dev/null @@ -1,13 +0,0 @@ -{ - "module": { - "name": "entry_test", - "type": "feature", - "deviceTypes": [ - "phone", - "tablet", - "2in1" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/RationalUseOfFrontEndResources/entry/src/test/List.test.ets b/RationalUseOfFrontEndResources/entry/src/test/List.test.ets deleted file mode 100644 index bb5b5c37..00000000 --- a/RationalUseOfFrontEndResources/entry/src/test/List.test.ets +++ /dev/null @@ -1,5 +0,0 @@ -import localUnitTest from './LocalUnit.test'; - -export default function testsuite() { - localUnitTest(); -} \ No newline at end of file diff --git a/RationalUseOfFrontEndResources/entry/src/test/LocalUnit.test.ets b/RationalUseOfFrontEndResources/entry/src/test/LocalUnit.test.ets deleted file mode 100644 index 165fc161..00000000 --- a/RationalUseOfFrontEndResources/entry/src/test/LocalUnit.test.ets +++ /dev/null @@ -1,33 +0,0 @@ -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; - -export default function localUnitTest() { - describe('localUnitTest', () => { - // Defines a test suite. Two parameters are supported: test suite name and test suite function. - beforeAll(() => { - // Presets an action, which is performed only once before all test cases of the test suite start. - // This API supports only one parameter: preset action function. - }); - beforeEach(() => { - // Presets an action, which is performed before each unit test case starts. - // The number of execution times is the same as the number of test cases defined by **it**. - // This API supports only one parameter: preset action function. - }); - afterEach(() => { - // Presets a clear action, which is performed after each unit test case ends. - // The number of execution times is the same as the number of test cases defined by **it**. - // This API supports only one parameter: clear action function. - }); - afterAll(() => { - // Presets a clear action, which is performed after all test cases of the test suite end. - // This API supports only one parameter: clear action function. - }); - it('assertContain', 0, () => { - // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. - let a = 'abc'; - let b = 'b'; - // Defines a variety of assertion methods, which are used to declare expected boolean conditions. - expect(a).assertContain(b); - expect(a).assertEqual(a); - }); - }); -} \ No newline at end of file -- Gitee