diff --git a/bundle.json b/bundle.json index 570c8e61203824d4efadcf57fa763e7dbbacb73e..366cc3667065f4197b8d1993d5f4b98340e13bb9 100755 --- a/bundle.json +++ b/bundle.json @@ -25,6 +25,9 @@ "sub_component": [ "//developtools/packing_tool:packing_tool", "//developtools/packing_tool:ohos_packing_tool" + ], + "test": [ + "//developtools/packing_tool/ohos_packing_tool/frameworks:unittest" ] } } diff --git a/ohos_packing_tool/frameworks/BUILD.gn b/ohos_packing_tool/frameworks/BUILD.gn index 78bb699a6b08dfcd807e0dede7937cfd9b81a347..69ad7ca0697e4b77456c7b9c63645078c3e8b2ed 100644 --- a/ohos_packing_tool/frameworks/BUILD.gn +++ b/ohos_packing_tool/frameworks/BUILD.gn @@ -32,3 +32,9 @@ ohos_executable("ohos_packing_tool") { subsystem_name = "developtools" part_name = "packing_tool" } +group("unittest") { + testonly = true + deps = [ + "test/unittest/shell_command_test:shell_command_test" + ] +} \ No newline at end of file diff --git a/ohos_packing_tool/frameworks/test/unittest/shell_command_test/BUILD.gn b/ohos_packing_tool/frameworks/test/unittest/shell_command_test/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..c36602b910b9d1df536635a4add3bcd1142e17a4 --- /dev/null +++ b/ohos_packing_tool/frameworks/test/unittest/shell_command_test/BUILD.gn @@ -0,0 +1,45 @@ +# Copyright (c) 2024 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/ohos.gni") +import("//build/test.gni") + +module_output_path = "developtools/packing_tool" + +ohos_unittest("shell_command_test") { + module_out_path = module_output_path + include_dirs = [ + "../../../include", + ] + sources = [ + "shell_command_test.cpp", + "../../../src/shell_command.cpp", + "../../../src/hap_packager.cpp", + "../../../src/hsp_packager.cpp", + "../../../src/packager.cpp", + ] + external_deps = [ + "json:nlohmann_json_static", + "cJSON:cjson", + "hilog:libhilog", + "zlib:libz", + "openssl:libssl_shared", + "openssl:libcrypto_shared", + ] +} + +group("unittest") { + testonly = true + + deps = [ ":shell_command_test" ] +} \ No newline at end of file diff --git a/ohos_packing_tool/frameworks/test/unittest/shell_command_test/shell_command_test.cpp b/ohos_packing_tool/frameworks/test/unittest/shell_command_test/shell_command_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..cca937e13f7633c194c930d63ebdb36fe0f8c797 --- /dev/null +++ b/ohos_packing_tool/frameworks/test/unittest/shell_command_test/shell_command_test.cpp @@ -0,0 +1,124 @@ +/* + * Copyright (c) 2024 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 + +#include +#include "constants.h" +#include "packager.h" +#include "hap_packager.h" +#include "hsp_packager.h" +#include "shell_command.h" + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { + +class ShellCommandTest : public testing::Test { +public: + ShellCommandTest() {} + virtual ~ShellCommandTest() {} + + static void SetUpTestCase(); + + static void TearDownTestCase(); + + void SetUp(); + + void TearDown(); +}; + +void ShellCommandTest::SetUpTestCase() {} + +void ShellCommandTest::TearDownTestCase() {} + +void ShellCommandTest::SetUp() {} + +void ShellCommandTest::TearDown() {} + +/* + * @tc.name: CreateCommandMap_0100 + * @tc.desc: CreateCommandMap. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ShellCommandTest, CreateCommandMap_0100, Function | MediumTest | Level1) +{ + int argc = 2; + const char *argv[] = { + "ohos_packing_tool", + "pack", + }; + + OHOS::AppPackingTool::ShellCommand shellcmd(argc, const_cast(argv), OHOS::AppPackingTool::TOOL_NAME); + int ret = shellcmd.CreateCommandMap(); + EXPECT_EQ(ret, 0); +} + +/* + * @tc.name: OnCommand_0300 + * @tc.desc: OnCommand. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ShellCommandTest, OnCommand_0300, Function | MediumTest | Level1) +{ + int argc = 2; + const char *argv[] = { + "ohos_packing_tool", + "help", + }; + + OHOS::AppPackingTool::ShellCommand shellcmd(argc, const_cast(argv), OHOS::AppPackingTool::TOOL_NAME); + int ret = shellcmd.CreateCommandMap(); + EXPECT_EQ(ret, 0); + ret = shellcmd.OnCommand(); + EXPECT_EQ(ret, 0); +} + +/* + * @tc.name: ExecCommand_0400 + * @tc.desc: ExecCommand. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ShellCommandTest, ExecCommand_0400, Function | MediumTest | Level1) +{ + int argc = 16; + const char *argv[] = { + "ohos_packing_tool", + "pack", + "--mode", + "hqf", + "--json-path", + "/data/testunpack/test_hqf_unpacking/patch.json", + "--lib-path", + "/data/testunpack/test_hqf_unpacking/libs", + "--resources-path", + "/data/testunpack/test_hqf_unpacking/resources", + "--ets-pat", + "/data/testunpack/test_hqf_unpacking/ets", + "--out-path", + "/data/hqfpacking/test_1.hqf", + "--force", + "true", + }; + + OHOS::AppPackingTool::ShellCommand shellcmd(argc, const_cast(argv), OHOS::AppPackingTool::TOOL_NAME); + std::string resultReceiver = shellcmd.ExecCommand(); + EXPECT_FALSE(resultReceiver.empty()); +} +} // namespace OHOS \ No newline at end of file