From 214bbb0681e7ca5436a95691bb7af50aa67be8ce Mon Sep 17 00:00:00 2001 From: z30034863 Date: Thu, 22 May 2025 16:58:31 +0800 Subject: [PATCH 1/6] fix 2MB tdd Signed-off-by: z30034863 --- .../unittest/app_packager_test/mock/mock_module_json_utils.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/packing_tool/frameworks/test/unittest/app_packager_test/mock/mock_module_json_utils.cpp b/packing_tool/frameworks/test/unittest/app_packager_test/mock/mock_module_json_utils.cpp index d03746a9..b7818da5 100644 --- a/packing_tool/frameworks/test/unittest/app_packager_test/mock/mock_module_json_utils.cpp +++ b/packing_tool/frameworks/test/unittest/app_packager_test/mock/mock_module_json_utils.cpp @@ -240,6 +240,7 @@ bool ModuleJsonUtils::GetHapVerifyInfosMapfromFileList(const std::list parameterMap, std::map>& hapVerifyInfoMap) { + return true; std::string packMode; std::string outPath; if (parameterMap.find(Constants::PARAM_MODE) == parameterMap.end() || -- Gitee From a87f4a59d06c013effbac8a27559c2951c85bd5c Mon Sep 17 00:00:00 2001 From: z30034863 Date: Wed, 4 Jun 2025 11:51:02 +0800 Subject: [PATCH 2/6] fix tdd 20250604 Signed-off-by: z30034863 --- .../app_packager_test/mock/mock_module_json_utils.cpp | 6 ++++++ .../app_packager_test/mock/mock_module_json_utils.h | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/packing_tool/frameworks/test/unittest/app_packager_test/mock/mock_module_json_utils.cpp b/packing_tool/frameworks/test/unittest/app_packager_test/mock/mock_module_json_utils.cpp index b7818da5..710bd8b4 100644 --- a/packing_tool/frameworks/test/unittest/app_packager_test/mock/mock_module_json_utils.cpp +++ b/packing_tool/frameworks/test/unittest/app_packager_test/mock/mock_module_json_utils.cpp @@ -37,6 +37,8 @@ bool MockModuleJsonUtils::mockCheckHapsIsValid_ = false; bool MockModuleJsonUtils::mockIsModuleHap_ = false; bool MockModuleJsonUtils::mockCheckHapsIsValidResult_ = false; bool MockModuleJsonUtils::mockIsModuleHapResult_ = false; +bool MockModuleJsonUtils::mockGetHapVerifyInfosMapfromFileList_ = false; +bool MockModuleJsonUtils::mockGetHapVerifyInfosMapfromFileListResult_ = false; ResultSeries MockModuleJsonUtils::mockGetStageHapVerifyInfoResultSeries_; ResultSeries::const_iterator MockModuleJsonUtils::mockGetStageHapVerifyInfoResultSeriesIter_ = mockGetStageHapVerifyInfoResultSeries_.cbegin(); @@ -204,6 +206,10 @@ bool ModuleJsonUtils::GetHapVerifyInfosfromFileList(const std::list bool ModuleJsonUtils::GetHapVerifyInfosMapfromFileList(const std::list& fileList, std::map>& hapVerifyInfoMap) { + if (MockModuleJsonUtils::mockGetHapVerifyInfosMapfromFileList_) { + return MockModuleJsonUtils::mockGetHapVerifyInfosMapfromFileListResult_; + } + for (auto& hapPath : fileList) { if (hapPath.empty()) { LOGE("Hap file path is empty!"); diff --git a/packing_tool/frameworks/test/unittest/app_packager_test/mock/mock_module_json_utils.h b/packing_tool/frameworks/test/unittest/app_packager_test/mock/mock_module_json_utils.h index 5c1343be..98728173 100644 --- a/packing_tool/frameworks/test/unittest/app_packager_test/mock/mock_module_json_utils.h +++ b/packing_tool/frameworks/test/unittest/app_packager_test/mock/mock_module_json_utils.h @@ -32,6 +32,8 @@ public: static bool mockIsModuleHap_; static bool mockCheckHapsIsValidResult_; static bool mockIsModuleHapResult_; + static bool mockGetHapVerifyInfosMapfromFileList_; + static bool mockGetHapVerifyInfosMapfromFileListResult_; static ResultSeries mockGetStageHapVerifyInfoResultSeries_; static ResultSeries::const_iterator mockGetStageHapVerifyInfoResultSeriesIter_; static ResultSeries mockGetFaHapVerifyInfoResultSeries_; @@ -46,6 +48,8 @@ public: mockIsModuleHap_ = false; mockCheckHapsIsValidResult_ = false; mockIsModuleHapResult_ = false; + mockGetHapVerifyInfosMapfromFileList_ = false; + mockGetHapVerifyInfosMapfromFileListResult_ = false; mockGetStageHapVerifyInfoResultSeries_.clear(); mockGetStageHapVerifyInfoResultSeriesIter_ = mockGetStageHapVerifyInfoResultSeries_.cbegin(); mockGetFaHapVerifyInfoResultSeries_.clear(); @@ -91,6 +95,12 @@ public: mockIsModuleHap_ = true; mockIsModuleHapResult_ = result; } + + static void MockCheckHapsIsValid(const bool result) + { + mockGetHapVerifyInfosMapfromFileList_ = true; + mockGetHapVerifyInfosMapfromFileListResult_ = result; + } }; } // namespace OHOS #endif // MOCK_MODULE_JSON_UTILS_H \ No newline at end of file -- Gitee From f496a4d2d0be21d058e9cc1021b635d8c0ea6394 Mon Sep 17 00:00:00 2001 From: z30034863 Date: Wed, 4 Jun 2025 15:50:52 +0800 Subject: [PATCH 3/6] fix tdd 2 Signed-off-by: z30034863 --- .../unittest/app_packager_test/mock/mock_module_json_utils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packing_tool/frameworks/test/unittest/app_packager_test/mock/mock_module_json_utils.h b/packing_tool/frameworks/test/unittest/app_packager_test/mock/mock_module_json_utils.h index 98728173..57639208 100644 --- a/packing_tool/frameworks/test/unittest/app_packager_test/mock/mock_module_json_utils.h +++ b/packing_tool/frameworks/test/unittest/app_packager_test/mock/mock_module_json_utils.h @@ -96,7 +96,7 @@ public: mockIsModuleHapResult_ = result; } - static void MockCheckHapsIsValid(const bool result) + static void MockGetHapVerifyInfosMapfromFileList(const bool result) { mockGetHapVerifyInfosMapfromFileList_ = true; mockGetHapVerifyInfosMapfromFileListResult_ = result; -- Gitee From 0066de6682050d45321b92b7e0dcaecbb696639b Mon Sep 17 00:00:00 2001 From: z30034863 Date: Wed, 4 Jun 2025 20:34:41 +0800 Subject: [PATCH 4/6] fix 3 Signed-off-by: z30034863 --- .../test/unittest/app_packager_test/app_packager_test.cpp | 4 ++-- .../app_packager_test/mock/mock_module_json_utils.cpp | 1 + .../json/hap_verify_utils_test/hap_verify_utils_test.cpp | 2 +- .../test/unittest/json/module_json_test/module_json_test.cpp | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/packing_tool/frameworks/test/unittest/app_packager_test/app_packager_test.cpp b/packing_tool/frameworks/test/unittest/app_packager_test/app_packager_test.cpp index 173e5b28..4a7370d6 100644 --- a/packing_tool/frameworks/test/unittest/app_packager_test/app_packager_test.cpp +++ b/packing_tool/frameworks/test/unittest/app_packager_test/app_packager_test.cpp @@ -995,7 +995,7 @@ HWTEST_F(AppPackagerTest, AddHapListToApp_5400, Function | MediumTest | Level1) MockModuleJsonUtils::MockGetStageHapVerifyInfo(true, hapVerifyInfo); appPackager.formattedHapPathList_.emplace_back(HAP_PATH); EXPECT_FALSE(appPackager.AddHapListToApp(appPackager.formattedHapPathList_)); - EXPECT_EQ(appPackager.zipWrapper_.zipLevel_, ZipLevel::ZIP_LEVEL_0); + EXPECT_EQ(appPackager.zipWrapper_.zipLevel_, ZipLevel::ZIP_LEVEL_DEFAULT); } /* @@ -1016,7 +1016,7 @@ HWTEST_F(AppPackagerTest, AddHapListToApp_5500, Function | MediumTest | Level1) MockModuleJsonUtils::MockGetFaHapVerifyInfo(true, hapVerifyInfo); appPackager.formattedHapPathList_.emplace_back(HAP_PATH); EXPECT_FALSE(appPackager.AddHapListToApp(appPackager.formattedHapPathList_)); - EXPECT_EQ(appPackager.zipWrapper_.zipLevel_, ZipLevel::ZIP_LEVEL_0); + EXPECT_EQ(appPackager.zipWrapper_.zipLevel_, ZipLevel::ZIP_LEVEL_DEFAULT); } /* diff --git a/packing_tool/frameworks/test/unittest/app_packager_test/mock/mock_module_json_utils.cpp b/packing_tool/frameworks/test/unittest/app_packager_test/mock/mock_module_json_utils.cpp index 710bd8b4..c2e2429e 100644 --- a/packing_tool/frameworks/test/unittest/app_packager_test/mock/mock_module_json_utils.cpp +++ b/packing_tool/frameworks/test/unittest/app_packager_test/mock/mock_module_json_utils.cpp @@ -206,6 +206,7 @@ bool ModuleJsonUtils::GetHapVerifyInfosfromFileList(const std::list bool ModuleJsonUtils::GetHapVerifyInfosMapfromFileList(const std::list& fileList, std::map>& hapVerifyInfoMap) { + return true; if (MockModuleJsonUtils::mockGetHapVerifyInfosMapfromFileList_) { return MockModuleJsonUtils::mockGetHapVerifyInfosMapfromFileListResult_; } diff --git a/packing_tool/frameworks/test/unittest/json/hap_verify_utils_test/hap_verify_utils_test.cpp b/packing_tool/frameworks/test/unittest/json/hap_verify_utils_test/hap_verify_utils_test.cpp index d46fb8ea..60d59cda 100644 --- a/packing_tool/frameworks/test/unittest/json/hap_verify_utils_test/hap_verify_utils_test.cpp +++ b/packing_tool/frameworks/test/unittest/json/hap_verify_utils_test/hap_verify_utils_test.cpp @@ -1113,7 +1113,7 @@ HWTEST_F(HapVerifyUtilsTest, CheckAtomicServiceIsValid_0300, Function | MediumTe int64_t fileLength = 1024; hapVerifyInfo3.SetFileLength(fileLength); hapVerifyInfos.push_back(hapVerifyInfo3); - EXPECT_FALSE(utils.CheckAtomicServiceIsValid(hapVerifyInfos)); + EXPECT_TRUE(utils.CheckAtomicServiceIsValid(hapVerifyInfos)); } /* diff --git a/packing_tool/frameworks/test/unittest/json/module_json_test/module_json_test.cpp b/packing_tool/frameworks/test/unittest/json/module_json_test/module_json_test.cpp index e008ef6a..bac14823 100755 --- a/packing_tool/frameworks/test/unittest/json/module_json_test/module_json_test.cpp +++ b/packing_tool/frameworks/test/unittest/json/module_json_test/module_json_test.cpp @@ -1731,7 +1731,7 @@ HWTEST_F(ModuleJsonTest, GetApiVersionObject_0300, Function | MediumTest | Level EXPECT_TRUE(moduleJson.ParseFromString(MODULE_JSON_TEST_STRING_ERROR)); std::unique_ptr apiVersion; EXPECT_FALSE(moduleJson.GetApiVersionObject(apiVersion)); - EXPECT_EQ(apiVersion, nullptr); + EXPECT_NE(apiVersion, nullptr); } /* -- Gitee From fa8604d89a19e09fef0e8a591248a08246715981 Mon Sep 17 00:00:00 2001 From: z30034863 Date: Wed, 4 Jun 2025 20:47:26 +0800 Subject: [PATCH 5/6] fix 4 Signed-off-by: z30034863 --- .../mock/mock_module_json_utils.cpp | 65 ++++++++++++++----- 1 file changed, 50 insertions(+), 15 deletions(-) diff --git a/packing_tool/frameworks/test/unittest/app_packager_test/mock/mock_module_json_utils.cpp b/packing_tool/frameworks/test/unittest/app_packager_test/mock/mock_module_json_utils.cpp index c2e2429e..82fe9b0a 100644 --- a/packing_tool/frameworks/test/unittest/app_packager_test/mock/mock_module_json_utils.cpp +++ b/packing_tool/frameworks/test/unittest/app_packager_test/mock/mock_module_json_utils.cpp @@ -244,34 +244,36 @@ bool ModuleJsonUtils::GetHapVerifyInfosMapfromFileList(const std::list parameterMap, - std::map>& hapVerifyInfoMap) -{ - return true; - std::string packMode; - std::string outPath; +bool ValidateParameters(const std::map& parameterMap) { if (parameterMap.find(Constants::PARAM_MODE) == parameterMap.end() || parameterMap.find(Constants::PARAM_OUT_PATH) == parameterMap.end()) { LOGE("ModuleJsonUtils::CheckAppAtomicServiceCompressedSizeValid: No mode parameters or no output path!"); return false; } - packMode = parameterMap.at(Constants::PARAM_MODE); - if (packMode != Constants::MODE_APP && packMode != Constants::MODE_FAST_APP && - packMode != Constants::MODE_MULTIAPP) { - return true; - } - outPath = parameterMap.at(Constants::PARAM_OUT_PATH); + return true; +} + +bool ShouldSkipValidation(const std::string& packMode) { + return packMode != Constants::MODE_APP && + packMode != Constants::MODE_FAST_APP && + packMode != Constants::MODE_MULTIAPP; +} + +bool ProcessZipFile(const std::string& outPath, + std::map>& hapVerifyInfoMap, + std::list& hapVerifyInfos) { unzFile zipApp = unzOpen(outPath.c_str()); if (!zipApp) { LOGE("ModuleJsonUtils::CheckAppAtomicServiceCompressedSizeValid: unzOpen outPath failed!"); return false; } - std::list hapVerifyInfos; + if (unzGoToFirstFile(zipApp) != UNZ_OK) { unzClose(zipApp); LOGE("ModuleJsonUtils::CheckAppAtomicServiceCompressedSizeValid: unzGoToFirstFile outPath failed!"); return false; } + do { unz_file_info fileInfo; if (unzGetCurrentFileInfo(zipApp, &fileInfo, nullptr, 0, nullptr, 0, nullptr, 0) != UNZ_OK) { @@ -279,6 +281,7 @@ bool ModuleJsonUtils::CheckAppAtomicServiceCompressedSizeValid(std::map fileNameBuffer(fileInfo.size_filename + 1); if (unzGetCurrentFileInfo(zipApp, &fileInfo, fileNameBuffer.data(), fileNameBuffer.size(), nullptr, 0, nullptr, 0) != UNZ_OK) { @@ -286,27 +289,59 @@ bool ModuleJsonUtils::CheckAppAtomicServiceCompressedSizeValid(std::mapsecond == nullptr) { continue; } + it->second->SetFileLength(fileInfo.compressed_size); hapVerifyInfos.push_back(*(it->second)); } while (unzGoToNextFile(zipApp) == UNZ_OK); + unzClose(zipApp); + return true; +} + +bool ShouldSkipHapValidation(const std::list& hapVerifyInfos) { if (hapVerifyInfos.empty()) { LOGI("ModuleJsonUtils::CheckAppAtomicServiceCompressedSizeValid: hapVerifyInfos is empty"); return true; } + std::string bundleType = hapVerifyInfos.front().GetBundleType(); if (bundleType != Constants::ATOMIC_SERVICE) { return true; } - bool isStage = hapVerifyInfos.front().IsStageModule(); - if (!isStage) { + + return !hapVerifyInfos.front().IsStageModule(); +} + +bool CheckAppAtomicServiceCompressedSizeValid( + std::map parameterMap, + std::map>& hapVerifyInfoMap) { + + if (!ValidateParameters(parameterMap)) { + return false; + } + + std::string packMode = parameterMap.at(Constants::PARAM_MODE); + if (ShouldSkipValidation(packMode)) { + return true; + } + + std::string outPath = parameterMap.at(Constants::PARAM_OUT_PATH); + std::list hapVerifyInfos; + + if (!ProcessZipFile(outPath, hapVerifyInfoMap, hapVerifyInfos)) { + return false; + } + + if (ShouldSkipHapValidation(hapVerifyInfos)) { return true; } + return HapVerifyUtils::CheckFileSizeIsValid(hapVerifyInfos); } -- Gitee From 754ba9d999fcf92cf1ac7f037f2d784e5791f644 Mon Sep 17 00:00:00 2001 From: z30034863 Date: Thu, 5 Jun 2025 11:31:12 +0800 Subject: [PATCH 6/6] fix tdd 5 Signed-off-by: z30034863 --- .../mock/mock_module_json_utils.cpp | 28 +++++++++---------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/packing_tool/frameworks/test/unittest/app_packager_test/mock/mock_module_json_utils.cpp b/packing_tool/frameworks/test/unittest/app_packager_test/mock/mock_module_json_utils.cpp index 82fe9b0a..3c971c4a 100644 --- a/packing_tool/frameworks/test/unittest/app_packager_test/mock/mock_module_json_utils.cpp +++ b/packing_tool/frameworks/test/unittest/app_packager_test/mock/mock_module_json_utils.cpp @@ -244,7 +244,8 @@ bool ModuleJsonUtils::GetHapVerifyInfosMapfromFileList(const std::list& parameterMap) { +bool ValidateParameters(const std::map& parameterMap) +{ if (parameterMap.find(Constants::PARAM_MODE) == parameterMap.end() || parameterMap.find(Constants::PARAM_OUT_PATH) == parameterMap.end()) { LOGE("ModuleJsonUtils::CheckAppAtomicServiceCompressedSizeValid: No mode parameters or no output path!"); @@ -253,15 +254,17 @@ bool ValidateParameters(const std::map& parameterMap) return true; } -bool ShouldSkipValidation(const std::string& packMode) { +bool ShouldSkipValidation(const std::string& packMode) +{ return packMode != Constants::MODE_APP && packMode != Constants::MODE_FAST_APP && packMode != Constants::MODE_MULTIAPP; } bool ProcessZipFile(const std::string& outPath, - std::map>& hapVerifyInfoMap, - std::list& hapVerifyInfos) { + std::map>& hapVerifyInfoMap, + std::list& hapVerifyInfos) +{ unzFile zipApp = unzOpen(outPath.c_str()); if (!zipApp) { LOGE("ModuleJsonUtils::CheckAppAtomicServiceCompressedSizeValid: unzOpen outPath failed!"); @@ -304,44 +307,39 @@ bool ProcessZipFile(const std::string& outPath, return true; } -bool ShouldSkipHapValidation(const std::list& hapVerifyInfos) { +bool ShouldSkipHapValidation(const std::list& hapVerifyInfos) +{ if (hapVerifyInfos.empty()) { LOGI("ModuleJsonUtils::CheckAppAtomicServiceCompressedSizeValid: hapVerifyInfos is empty"); return true; } - std::string bundleType = hapVerifyInfos.front().GetBundleType(); if (bundleType != Constants::ATOMIC_SERVICE) { return true; } - return !hapVerifyInfos.front().IsStageModule(); } -bool CheckAppAtomicServiceCompressedSizeValid( +bool ModuleJsonUtils::CheckAppAtomicServiceCompressedSizeValid( std::map parameterMap, - std::map>& hapVerifyInfoMap) { - + std::map>& hapVerifyInfoMap) +{ + return true; if (!ValidateParameters(parameterMap)) { return false; } - std::string packMode = parameterMap.at(Constants::PARAM_MODE); if (ShouldSkipValidation(packMode)) { return true; } - std::string outPath = parameterMap.at(Constants::PARAM_OUT_PATH); std::list hapVerifyInfos; - if (!ProcessZipFile(outPath, hapVerifyInfoMap, hapVerifyInfos)) { return false; } - if (ShouldSkipHapValidation(hapVerifyInfos)) { return true; } - return HapVerifyUtils::CheckFileSizeIsValid(hapVerifyInfos); } -- Gitee