From 5b6218178c8f3393ee92236db951f47506fcfbd9 Mon Sep 17 00:00:00 2001 From: Tintin9529 Date: Tue, 24 Sep 2024 19:42:34 +0800 Subject: [PATCH] add tdd Signed-off-by: Tintin9529 --- .../frameworks/test/unittest/BUILD.gn | 1 + .../test/unittest/hqf_verify_test/BUILD.gn | 50 ++++++ .../hqf_verify_test/hqf_verify_test.cpp | 162 ++++++++++++++++++ 3 files changed, 213 insertions(+) create mode 100644 packing_tool/frameworks/test/unittest/hqf_verify_test/BUILD.gn create mode 100644 packing_tool/frameworks/test/unittest/hqf_verify_test/hqf_verify_test.cpp diff --git a/packing_tool/frameworks/test/unittest/BUILD.gn b/packing_tool/frameworks/test/unittest/BUILD.gn index 9e15625d..d7427540 100644 --- a/packing_tool/frameworks/test/unittest/BUILD.gn +++ b/packing_tool/frameworks/test/unittest/BUILD.gn @@ -22,6 +22,7 @@ group("unittest") { "fast_app_packager_test:unittest", "hap_packager_test:unittest", "hqf_packager_test:unittest", + "hqf_verify_test:unittest", "hsp_packager_test:unittest", "json/distro_filter_test:unittest", "json/hap_verify_utils_test:unittest", diff --git a/packing_tool/frameworks/test/unittest/hqf_verify_test/BUILD.gn b/packing_tool/frameworks/test/unittest/hqf_verify_test/BUILD.gn new file mode 100644 index 00000000..bd730c9d --- /dev/null +++ b/packing_tool/frameworks/test/unittest/hqf_verify_test/BUILD.gn @@ -0,0 +1,50 @@ +# 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") + +config("hqf_verify_config") { + include_dirs = [ + "../../../include", + "../../../include/json", + ] + + cflags_cc = [ "-fexceptions" ] + cflags_objcc = cflags_cc +} + +module_output_path = "developtools/packing_tool" + +ohos_unittest("hqf_verify_test") { + module_out_path = module_output_path + public_configs = [ ":hqf_verify_config" ] + sources = [ + "../../../src/hqf_verify.cpp", + "../../../src/log.cpp", + "../../../src/utils.cpp", + "hqf_verify_test.cpp", + ] + external_deps = [ + "bounds_checking_function:libsec_static", + "cJSON:cjson_static", + "hilog:libhilog", + "openssl:libcrypto_shared", + "zlib:libz", + ] +} + +group("unittest") { + testonly = true + deps = [ ":hqf_verify_test" ] +} diff --git a/packing_tool/frameworks/test/unittest/hqf_verify_test/hqf_verify_test.cpp b/packing_tool/frameworks/test/unittest/hqf_verify_test/hqf_verify_test.cpp new file mode 100644 index 00000000..ea83a616 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/hqf_verify_test/hqf_verify_test.cpp @@ -0,0 +1,162 @@ +/* + * 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 + +#define private public +#define protected public +#include "hqf_verify.h" +#undef private +#undef protected +#include "hqf_info.h" +#include "utils.h" + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { + +class HqfVerifyTest : public testing::Test { +public: + HqfVerifyTest() {} + virtual ~HqfVerifyTest() {} + + static void SetUpTestCase(); + + static void TearDownTestCase(); + + void SetUp(); + + void TearDown(); +}; + +void HqfVerifyTest::SetUpTestCase() {} + +void HqfVerifyTest::TearDownTestCase() {} + +void HqfVerifyTest::SetUp() {} + +void HqfVerifyTest::TearDown() {} + +using namespace AppPackingTool; + +void CreateHqfInfo(HqfInfo &hqfInfo) +{ + std::string bundleName("bundleName"); + hqfInfo.SetBundleName(bundleName); + int32_t versionCode = 1; + hqfInfo.SetVersionCode(versionCode); + std::string versionName("2.1"); + hqfInfo.SetVersionName(versionName); + hqfInfo.SetPatchVersionCode(versionCode); + hqfInfo.SetPatchVersionName(versionName); + std::string moduleName("moduleName"); + hqfInfo.SetModuleName(moduleName); + std::list deviceTypes = {"deviceTypes"}; + hqfInfo.SetDeviceTypes(deviceTypes); +} + +/* + * @tc.name: CheckHQFIsValid_0100 + * @tc.desc: CheckHQFIsValid. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HqfVerifyTest, CheckHQFIsValid_0100, Function | MediumTest | Level1) +{ + std::vector hqfInfos; + EXPECT_FALSE(OHOS::AppPackingTool::HQFVerify::CheckHQFIsValid(hqfInfos)); + + HqfInfo hqfInfo; + CreateHqfInfo(hqfInfo); + hqfInfos.emplace_back(hqfInfo); + EXPECT_TRUE(OHOS::AppPackingTool::HQFVerify::CheckHQFIsValid(hqfInfos)); + + HqfInfo hqfInfo1; + CreateHqfInfo(hqfInfo1); + hqfInfos.emplace_back(hqfInfo1); + EXPECT_FALSE(OHOS::AppPackingTool::HQFVerify::CheckHQFIsValid(hqfInfos)); + + std::string bundleName = ""; + hqfInfos.at(0).SetBundleName(bundleName); + EXPECT_FALSE(OHOS::AppPackingTool::HQFVerify::CheckHQFIsValid(hqfInfos)); +} + +/* + * @tc.name: CheckAppFields_0200 + * @tc.desc: CheckAppFields. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HqfVerifyTest, CheckAppFields_0200, Function | MediumTest | Level1) +{ + std::vector hqfInfos; + HqfInfo hqfInfo; + std::string bundleName("bundleName"); + hqfInfo.SetBundleName(bundleName); + int32_t versionCode = 2; + hqfInfo.SetVersionCode(versionCode); + hqfInfo.SetPatchVersionCode(versionCode); + std::string versionName; + hqfInfo.SetVersionName(versionName); + hqfInfo.SetPatchVersionName(versionName); + hqfInfos.emplace_back(hqfInfo); + EXPECT_FALSE(OHOS::AppPackingTool::HQFVerify::CheckAppFields(hqfInfos)); + + versionName = "2.1"; + hqfInfos.at(0).SetVersionName(versionName); + EXPECT_FALSE(OHOS::AppPackingTool::HQFVerify::CheckAppFields(hqfInfos)); + + std::string patchVersionName = "2.1"; + hqfInfos.at(0).SetPatchVersionName(patchVersionName); + HqfInfo hqfInfo1; + CreateHqfInfo(hqfInfo1); + hqfInfos.emplace_back(hqfInfo1); + EXPECT_FALSE(OHOS::AppPackingTool::HQFVerify::CheckAppFields(hqfInfos)); + + versionCode = 1; + hqfInfos.at(0).SetVersionCode(versionCode); + EXPECT_FALSE(OHOS::AppPackingTool::HQFVerify::CheckAppFields(hqfInfos)); +} + +/* + * @tc.name: CheckModuleIsDuplicated_0300 + * @tc.desc: CheckModuleIsDuplicated. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HqfVerifyTest, CheckHQFIsValid_0300, Function | MediumTest | Level1) +{ + HqfInfo hqfInfo; + CreateHqfInfo(hqfInfo); + std::string moduleName("test"); + hqfInfo.SetModuleName(moduleName); + + HqfInfo hqfInfo1; + CreateHqfInfo(hqfInfo1); + EXPECT_FALSE(OHOS::AppPackingTool::HQFVerify::CheckModuleIsDuplicated(hqfInfo, hqfInfo1)); + + moduleName = "moduleName"; + hqfInfo.SetModuleName(moduleName); + EXPECT_TRUE(OHOS::AppPackingTool::HQFVerify::CheckModuleIsDuplicated(hqfInfo, hqfInfo1)); + + std::list deviceTypes = {"test"}; + hqfInfo1.SetDeviceTypes(deviceTypes); + EXPECT_FALSE(OHOS::AppPackingTool::HQFVerify::CheckModuleIsDuplicated(hqfInfo, hqfInfo1)); +} +} + -- Gitee