diff --git a/BUILD.gn b/BUILD.gn index ce5fafb7ea6c1a87dc396dd88cb55e914ce265f8..40f6714f9308fd8978671ea594de91fcd81aa359 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -15,8 +15,7 @@ import("//build/ohos.gni") import("//build/test.gni") import("./restool.gni") -ohos_executable("restool") { - sources = [ +restool_source = [ "src/append_compiler.cpp", "src/binary_file_packer.cpp", "src/cmd/cmd_parser.cpp", @@ -50,11 +49,17 @@ ohos_executable("restool") { "src/resource_packer_factory.cpp", "src/resource_table.cpp", "src/resource_util.cpp", - "src/restool.cpp", "src/restool_errors.cpp", "src/select_compile_parse.cpp", "src/thread_pool.cpp", "src/translatable_parser.cpp", +] + +ohos_executable("restool") { + sources = restool_source + + sources += [ + "src/restool.cpp", ] include_dirs = [ @@ -86,8 +91,46 @@ ohos_executable("restool") { part_name = "global_resource_tool" } -ohos_unittest_py("restool_test") { - sources = [ "test/test.py" ] +group("restool_test") { + testonly = true + deps = [ + ":restool_ut", + ":restool_ut(${host_toolchain})", + ] +} + +ohos_unittest("restool_ut") { + sources = restool_source + sources += [ + "test/uttest/src/resource_dumper_test.cpp" + ] + module_out_path = "developtools/restool" + + use_exceptions = true + + cflags = [ "-std=c++17" ] + + include_dirs = [ + "include", + "test/uttest/include", + "//third_party/bounds_checking_function/include", + ] + + deps = [ + "//third_party/bounds_checking_function:libsec_static", + "//third_party/cJSON:cjson_static", + "//third_party/libpng:libpng_static", + ] + + if (is_arkui_x) { + deps += [ "//third_party/zlib:libz" ] + } else { + external_deps = [ "zlib:libz" ] + } + + public_external_deps = [ + "googletest:gmock_main" + ] } ohos_copy("restool_id_defined") { diff --git a/test/test.py b/test/BUILD.gn similarity index 56% rename from test/test.py rename to test/BUILD.gn index fe57518932afd4f09ad631e4a1460a2050d1a301..90763fd031595ee500a50bbc03c5332a582ce9c4 100644 --- a/test/test.py +++ b/test/BUILD.gn @@ -1,6 +1,4 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -# Copyright (c) 2021 Huawei Device Co., Ltd. +# Copyright (c) 2025 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,15 +11,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -import os -import sys +import("//build/test.gni") -restool_cmd = sys.argv[1] -output_path = sys.argv[2] -run_cmd = restool_cmd -run_cmd = run_cmd + " -i " + os.path.join(".") -run_cmd = run_cmd + " -o " + output_path -run_cmd = run_cmd + " -r " + os.path.join(output_path, "ResourceTable.h") -run_cmd = run_cmd + " -p com.example.myapplication" -os.system(run_cmd) \ No newline at end of file diff --git a/test/config.json b/test/config.json deleted file mode 100644 index 390d25badcd1a38e21a27243425ef4e31a61f293..0000000000000000000000000000000000000000 --- a/test/config.json +++ /dev/null @@ -1,60 +0,0 @@ -{ - "app": { - "bundleName": "com.example.myapplication", - "vendor": "example", - "version": { - "code": 1, - "name": "1.0" - }, - "apiVersion": { - "compatible": 4, - "target": 5 - } - }, - "deviceConfig": {}, - "module": { - "package": "com.example.myapplication", - "name": ".MyApplication", - "deviceType": [ - "phone" - ], - "distro": { - "deliveryWithInstall": true, - "moduleName": "entry", - "moduleType": "entry" - }, - "abilities": [ - { - "visible": true, - "skills": [ - { - "entities": [ - "entity.system.home" - ], - "actions": [ - "action.system.home" - ] - } - ], - "name": "com.example.myapplication.MainAbility", - "icon": "$media:icon", - "description": "$string:mainability_description", - "label": "MyApplication", - "type": "page", - "launchType": "standard" - } - ], - "js": [ - { - "pages": [ - "pages/index/index" - ], - "name": "default", - "window": { - "designWidth": 720, - "autoDesignWidth": false - } - } - ] - } -} \ No newline at end of file diff --git a/test/resources/base/element/strings.json b/test/data/resources/base/element/strings.json similarity index 100% rename from test/resources/base/element/strings.json rename to test/data/resources/base/element/strings.json diff --git a/test/resources/base/media/icon.png b/test/data/resources/base/media/icon.png similarity index 100% rename from test/resources/base/media/icon.png rename to test/data/resources/base/media/icon.png diff --git a/test/uttest/include/common.h b/test/uttest/include/common.h new file mode 100644 index 0000000000000000000000000000000000000000..0f109d711df9416d8ff3584d0d5220b459224c76 --- /dev/null +++ b/test/uttest/include/common.h @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 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. + */ + #ifndef OHOS_RESTOOL_TEST_COMMON_H + #define OHOS_RESTOOL_TEST_COMMON_H + + #include "gtest/gtest.h" + + #endif \ No newline at end of file diff --git a/test/uttest/src/resource_dumper_test.cpp b/test/uttest/src/resource_dumper_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..cf8265210b4822ec2816a72fe1f9bf2becb269ab --- /dev/null +++ b/test/uttest/src/resource_dumper_test.cpp @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2025 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 "common.h" + + +namespace { +class ResourceDumperTest : public testing::Test +{ + void SetUp() override; + + void TearDown() override; + +}; + +void ResourceDumperTest::SetUp() +{} + +void ResourceDumperTest::TearDown() +{} + +TEST_F(ResourceDumperTest, TestDemo) +{ + EXPECT_TRUE(1==1); +} + +};