From 214bbb0681e7ca5436a95691bb7af50aa67be8ce Mon Sep 17 00:00:00 2001 From: z30034863 Date: Thu, 22 May 2025 16:58:31 +0800 Subject: [PATCH 01/15] 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 02/15] 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 03/15] 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 04/15] 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 05/15] 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 06/15] 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 From f026113755e0edce5557abd219643c840386a3f9 Mon Sep 17 00:00:00 2001 From: z30034863 Date: Thu, 5 Jun 2025 18:16:30 +0800 Subject: [PATCH 07/15] fix tdd 6 Signed-off-by: z30034863 --- .../unittest/app_packager_test/app_packager_test.cpp | 8 ++++++++ .../app_packager_test/mock/mock_module_json_utils.cpp | 8 ++++++-- .../app_packager_test/mock/mock_module_json_utils.h | 10 ++++++++++ 3 files changed, 24 insertions(+), 2 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 4a7370d6..cf4218d2 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 @@ -93,6 +93,8 @@ HWTEST_F(AppPackagerTest, InitAllowedParam_0100, Function | MediumTest | Level1) }; OHOS::AppPackingTool::AppPackager appPackager(parameterMap, resultReceiver); + MockModuleJsonUtils::MockCheckAppAtomicServiceCompressedSizeValid(true); + MockModuleJsonUtils::MockGetHapVerifyInfosMapfromFileList(true); EXPECT_EQ(appPackager.InitAllowedParam(), ERR_OK); EXPECT_EQ(appPackager.PreProcess(), ERR_OK); EXPECT_EQ(appPackager.Process(), ERR_OK); @@ -994,6 +996,8 @@ HWTEST_F(AppPackagerTest, AddHapListToApp_5400, Function | MediumTest | Level1) hapVerifyInfo.SetDebug(true); MockModuleJsonUtils::MockGetStageHapVerifyInfo(true, hapVerifyInfo); appPackager.formattedHapPathList_.emplace_back(HAP_PATH); + MockModuleJsonUtils::MockCheckAppAtomicServiceCompressedSizeValid(true); + MockModuleJsonUtils::MockGetHapVerifyInfosMapfromFileList(true); EXPECT_FALSE(appPackager.AddHapListToApp(appPackager.formattedHapPathList_)); EXPECT_EQ(appPackager.zipWrapper_.zipLevel_, ZipLevel::ZIP_LEVEL_DEFAULT); } @@ -1015,6 +1019,8 @@ HWTEST_F(AppPackagerTest, AddHapListToApp_5500, Function | MediumTest | Level1) hapVerifyInfo.SetDebug(true); MockModuleJsonUtils::MockGetFaHapVerifyInfo(true, hapVerifyInfo); appPackager.formattedHapPathList_.emplace_back(HAP_PATH); + MockModuleJsonUtils::MockCheckAppAtomicServiceCompressedSizeValid(true); + MockModuleJsonUtils::MockGetHapVerifyInfosMapfromFileList(true); EXPECT_FALSE(appPackager.AddHapListToApp(appPackager.formattedHapPathList_)); EXPECT_EQ(appPackager.zipWrapper_.zipLevel_, ZipLevel::ZIP_LEVEL_DEFAULT); } @@ -1118,6 +1124,8 @@ HWTEST_F(AppPackagerTest, CompressAppMode_6100, Function | MediumTest | Level1) OHOS::AppPackingTool::AppPackager appPackager(parameterMap, resultReceiver); MockModuleJsonUtils::MockCheckHapsIsValid(true); + MockModuleJsonUtils::MockCheckAppAtomicServiceCompressedSizeValid(true); + MockModuleJsonUtils::MockGetHapVerifyInfosMapfromFileList(true); EXPECT_TRUE(appPackager.CompressAppMode()); } 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 3c971c4a..4c800e65 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::mockCheckAppAtomicServiceCompressedSizeValid_ = false; +bool MockModuleJsonUtils::mockCheckAppAtomicServiceCompressedSizeValidResult_ = false; bool MockModuleJsonUtils::mockGetHapVerifyInfosMapfromFileList_ = false; bool MockModuleJsonUtils::mockGetHapVerifyInfosMapfromFileListResult_ = false; ResultSeries MockModuleJsonUtils::mockGetStageHapVerifyInfoResultSeries_; @@ -206,7 +208,6 @@ bool ModuleJsonUtils::GetHapVerifyInfosfromFileList(const std::list bool ModuleJsonUtils::GetHapVerifyInfosMapfromFileList(const std::list& fileList, std::map>& hapVerifyInfoMap) { - return true; if (MockModuleJsonUtils::mockGetHapVerifyInfosMapfromFileList_) { return MockModuleJsonUtils::mockGetHapVerifyInfosMapfromFileListResult_; } @@ -324,7 +325,10 @@ bool ModuleJsonUtils::CheckAppAtomicServiceCompressedSizeValid( std::map parameterMap, std::map>& hapVerifyInfoMap) { - return true; + if (MockModuleJsonUtils::mockCheckAppAtomicServiceCompressedSizeValid_) { + return MockModuleJsonUtils::mockCheckAppAtomicServiceCompressedSizeValidResult_; + } + if (!ValidateParameters(parameterMap)) { return false; } 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 57639208..fdb8f6f0 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 mockCheckAppAtomicServiceCompressedSizeValid_; + static bool mockCheckAppAtomicServiceCompressedSizeValidResult_; static bool mockGetHapVerifyInfosMapfromFileList_; static bool mockGetHapVerifyInfosMapfromFileListResult_; static ResultSeries mockGetStageHapVerifyInfoResultSeries_; @@ -48,6 +50,8 @@ public: mockIsModuleHap_ = false; mockCheckHapsIsValidResult_ = false; mockIsModuleHapResult_ = false; + mockCheckAppAtomicServiceCompressedSizeValid_ = false; + mockCheckAppAtomicServiceCompressedSizeValidResult_ = false; mockGetHapVerifyInfosMapfromFileList_ = false; mockGetHapVerifyInfosMapfromFileListResult_ = false; mockGetStageHapVerifyInfoResultSeries_.clear(); @@ -96,6 +100,12 @@ public: mockIsModuleHapResult_ = result; } + static void MockCheckAppAtomicServiceCompressedSizeValid(const bool result) + { + mockCheckAppAtomicServiceCompressedSizeValid_ = true; + mockCheckAppAtomicServiceCompressedSizeValidResult_ = result; + } + static void MockGetHapVerifyInfosMapfromFileList(const bool result) { mockGetHapVerifyInfosMapfromFileList_ = true; -- Gitee From 97ed0c4fcc105cc22e35b4ac8ebf75301d4d3f49 Mon Sep 17 00:00:00 2001 From: z30034863 Date: Thu, 5 Jun 2025 20:37:55 +0800 Subject: [PATCH 08/15] fix 6 Signed-off-by: z30034863 --- .../unittest/fast_app_packager_test/BUILD.gn | 1 + .../fast_app_packager_test.cpp | 3 + .../mock/mock_module_json_utils.cpp | 407 ++++++++++++++++++ .../mock/mock_module_json_utils.h | 116 +++++ .../unittest/multiapp_packager_test/BUILD.gn | 1 + .../mock/mock_module_json_utils.cpp | 407 ++++++++++++++++++ .../mock/mock_module_json_utils.h | 116 +++++ .../multiapp_packager_test.cpp | 9 + 8 files changed, 1060 insertions(+) create mode 100644 packing_tool/frameworks/test/unittest/fast_app_packager_test/mock/mock_module_json_utils.cpp create mode 100644 packing_tool/frameworks/test/unittest/fast_app_packager_test/mock/mock_module_json_utils.h create mode 100644 packing_tool/frameworks/test/unittest/multiapp_packager_test/mock/mock_module_json_utils.cpp create mode 100644 packing_tool/frameworks/test/unittest/multiapp_packager_test/mock/mock_module_json_utils.h diff --git a/packing_tool/frameworks/test/unittest/fast_app_packager_test/BUILD.gn b/packing_tool/frameworks/test/unittest/fast_app_packager_test/BUILD.gn index 1a7dfa4e..00d65bbe 100644 --- a/packing_tool/frameworks/test/unittest/fast_app_packager_test/BUILD.gn +++ b/packing_tool/frameworks/test/unittest/fast_app_packager_test/BUILD.gn @@ -47,6 +47,7 @@ ohos_unittest("fast_app_packager_test") { "../../../src/zip_utils.cpp", "../../../src/zip_wrapper.cpp", "fast_app_packager_test.cpp", + "mock/mock_module_json_utils.cpp", ] external_deps = [ "bounds_checking_function:libsec_static", diff --git a/packing_tool/frameworks/test/unittest/fast_app_packager_test/fast_app_packager_test.cpp b/packing_tool/frameworks/test/unittest/fast_app_packager_test/fast_app_packager_test.cpp index 263998e7..aac39e0a 100644 --- a/packing_tool/frameworks/test/unittest/fast_app_packager_test/fast_app_packager_test.cpp +++ b/packing_tool/frameworks/test/unittest/fast_app_packager_test/fast_app_packager_test.cpp @@ -21,6 +21,7 @@ #define private public #define protected public #include "fast_app_packager.h" +#include "mock/mock_module_json_utils.h" #undef private #undef protected @@ -173,6 +174,8 @@ HWTEST_F(FastAppPackagerTest, fastAppPackager_0100, Function | MediumTest | Leve "/data/test/resource/packingtool/test_file/pack.info"); system("cp -f /data/test/resource/packingtool/test_file/hap/entry/pack.json " "/data/test/resource/packingtool/test_file/hap/entry/pack.info"); + MockModuleJsonUtils::MockCheckAppAtomicServiceCompressedSizeValid(true); + MockModuleJsonUtils::MockGetHapVerifyInfosMapfromFileList(true); EXPECT_EQ(fastAppackager.InitAllowedParam(), 0); EXPECT_EQ(fastAppackager.PreProcess(), 0); EXPECT_EQ(fastAppackager.Process(), 0); diff --git a/packing_tool/frameworks/test/unittest/fast_app_packager_test/mock/mock_module_json_utils.cpp b/packing_tool/frameworks/test/unittest/fast_app_packager_test/mock/mock_module_json_utils.cpp new file mode 100644 index 00000000..4c800e65 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/fast_app_packager_test/mock/mock_module_json_utils.cpp @@ -0,0 +1,407 @@ +/* + * 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 "module_json_utils.h" + +#include +#include +#include + +#include "hap_verify_utils.h" +#include "log.h" +#include "mock_module_json_utils.h" +#include "module_json.h" +#include "utils.h" +#include "zip_utils.h" +#include "constants.h" + +namespace fs = std::filesystem; + +namespace OHOS { + +bool MockModuleJsonUtils::mockGetStageHapVerifyInfo_ = false; +bool MockModuleJsonUtils::mockGetFaHapVerifyInfo_ = false; +bool MockModuleJsonUtils::mockCheckHapsIsValid_ = false; +bool MockModuleJsonUtils::mockIsModuleHap_ = false; +bool MockModuleJsonUtils::mockCheckHapsIsValidResult_ = false; +bool MockModuleJsonUtils::mockIsModuleHapResult_ = false; +bool MockModuleJsonUtils::mockCheckAppAtomicServiceCompressedSizeValid_ = false; +bool MockModuleJsonUtils::mockCheckAppAtomicServiceCompressedSizeValidResult_ = false; +bool MockModuleJsonUtils::mockGetHapVerifyInfosMapfromFileList_ = false; +bool MockModuleJsonUtils::mockGetHapVerifyInfosMapfromFileListResult_ = false; +ResultSeries MockModuleJsonUtils::mockGetStageHapVerifyInfoResultSeries_; +ResultSeries::const_iterator + MockModuleJsonUtils::mockGetStageHapVerifyInfoResultSeriesIter_ = mockGetStageHapVerifyInfoResultSeries_.cbegin(); +ResultSeries MockModuleJsonUtils::mockGetFaHapVerifyInfoResultSeries_; +ResultSeries::const_iterator + MockModuleJsonUtils::mockGetFaHapVerifyInfoResultSeriesIter_ = mockGetFaHapVerifyInfoResultSeries_.cbegin(); + +namespace AppPackingTool { +namespace { +const std::string MODULE_JSON = "module.json"; +const std::string CONFIG_JSON = "config.json"; +const std::string HAP_SUFFIX = ".hap"; +const std::string HSP_SUFFIX = ".hsp"; +const int32_t SHARED_APP_HSP_LIMIT = 1; +const std::string TYPE_SHARED = "shared"; +const std::string INCLUDE = "include"; +const std::string EXCLUDE = "exclude"; +const std::string ATOMIC_SERVICE = "atomicService"; +static int32_t g_entryModuleSizeLimit = 2; +static int32_t g_notEntryModuleSizeLimit = 2; +static int32_t g_sumModuleSizeLimit = 10; +} + +// java : parseStageHapVerifyInfo +bool ModuleJsonUtils::GetStageHapVerifyInfo(const std::string& hapFilePath, HapVerifyInfo& hapVerifyInfo) +{ + if (MockModuleJsonUtils::mockGetStageHapVerifyInfo_) { + const bool result = MockModuleJsonUtils::mockGetStageHapVerifyInfoResultSeriesIter_->first; + hapVerifyInfo = MockModuleJsonUtils::mockGetStageHapVerifyInfoResultSeriesIter_->second; + + const auto next = MockModuleJsonUtils::mockGetStageHapVerifyInfoResultSeriesIter_ + 1; + if (next != MockModuleJsonUtils::mockGetStageHapVerifyInfoResultSeries_.cend()) { + MockModuleJsonUtils::mockGetStageHapVerifyInfoResultSeriesIter_ = next; + } + + return result; + } + + std::string fileContent; + std::map resourceMap; + int64_t fileLength = Utils::GetFileLength(hapFilePath); + if (fileLength < 0) { + LOGE("Get hap file length failed! hapFile=%s", hapFilePath.c_str()); + return false; + } + if (!ZipUtils::GetFileContentFromZip(hapFilePath, MODULE_JSON, fileContent)) { + LOGE("Get module.json content from hap file failed! hapFile=%s", hapFilePath.c_str()); + return false; + } + if (!ZipUtils::GetResourceMapFromZip(hapFilePath, resourceMap)) { + LOGE("Get resouce map from hap file failed! hapFile=%s", hapFilePath.c_str()); + return false; + } + hapVerifyInfo.SetResourceMap(resourceMap); + hapVerifyInfo.SetProfileStr(fileContent); + hapVerifyInfo.SetStageModule(true); + hapVerifyInfo.SetFileLength(fileLength); + ModuleJson moduleJson; + if (!moduleJson.ParseFromString(fileContent)) { + LOGE("Parse json string failed!"); + return false; + } + if (!moduleJson.GetStageHapVerifyInfo(hapVerifyInfo)) { + LOGE("Get stage hap verify info failed!"); + return false; + } + return true; +} + +bool ModuleJsonUtils::GetFaHapVerifyInfo(const std::string& hapFilePath, HapVerifyInfo& hapVerifyInfo) +{ + if (MockModuleJsonUtils::mockGetFaHapVerifyInfo_) { + const bool result = MockModuleJsonUtils::mockGetFaHapVerifyInfoResultSeriesIter_->first; + hapVerifyInfo = MockModuleJsonUtils::mockGetFaHapVerifyInfoResultSeriesIter_->second; + + const auto next = MockModuleJsonUtils::mockGetFaHapVerifyInfoResultSeriesIter_ + 1; + if (next != MockModuleJsonUtils::mockGetFaHapVerifyInfoResultSeries_.cend()) { + MockModuleJsonUtils::mockGetFaHapVerifyInfoResultSeriesIter_ = next; + } + + return result; + } + + std::string fileContent; + int64_t fileLength = Utils::GetFileLength(hapFilePath); + if (fileLength < 0) { + LOGE("Get hap file length failed! hapFile=%s", hapFilePath.c_str()); + return false; + } + if (!ZipUtils::GetFileContentFromZip(hapFilePath, CONFIG_JSON, fileContent)) { + LOGE("Get module.json content from hap file failed! hapFile=%s", hapFilePath.c_str()); + return false; + } + ModuleJson moduleJson; + if (!moduleJson.ParseFromString(fileContent)) { + LOGE("Parse json string failed!"); + return false; + } + if (!moduleJson.GetFaHapVerifyInfo(hapVerifyInfo)) { + LOGE("Get FA hap verify info failed!"); + return false; + } + hapVerifyInfo.SetProfileStr(fileContent); + hapVerifyInfo.SetStageModule(false); + hapVerifyInfo.SetFileLength(fileLength); + return true; +} + +// java : Compressor::checkSharedAppIsValid / HapVerify::checkSharedApppIsValid +bool ModuleJsonUtils::CheckSharedAppIsValid(const std::list& hapVerifyInfos, bool& isOverlay) +{ + if (hapVerifyInfos.empty()) { + LOGE("hapVerifyInfos is empty"); + return false; + } + if (hapVerifyInfos.size() > SHARED_APP_HSP_LIMIT) { + LOGE("hapVerifyInfos size is over than %d", SHARED_APP_HSP_LIMIT); + return false; + } + for (auto& hapVerifyInfo : hapVerifyInfos) { + if (!hapVerifyInfo.GetTargetBundleName().empty()) { + isOverlay = true; + return true; + } + } + return HapVerifyUtils::CheckSharedAppIsValid(hapVerifyInfos); +} + +bool ModuleJsonUtils::GetHapVerifyInfosfromFileList(const std::list& fileList, + std::list& hapVerifyInfos) +{ + for (auto& hapPath : fileList) { + if (hapPath.empty()) { + LOGE("Hap file path is empty!"); + return false; + } + fs::path fsHapPath(hapPath); + std::string fileName = fsHapPath.filename().string(); + if (fileName.empty()) { + LOGE("Hap file name is empty!"); + return false; + } + std::transform(fileName.begin(), fileName.end(), fileName.begin(), ::tolower); + if (!Utils::EndsWith(fileName, HAP_SUFFIX) && !Utils::EndsWith(fileName, HSP_SUFFIX)) { + LOGE("Hap file is not a hap or hsp file!"); + return false; + } + HapVerifyInfo hapVerifyInfo; + if (IsModuleHap(hapPath)) { + if (!GetStageHapVerifyInfo(hapPath, hapVerifyInfo)) { + LOGE("GetStageHapVerifyInfo failed!"); + return false; + } + } else { + if (!GetFaHapVerifyInfo(hapPath, hapVerifyInfo)) { + LOGE("GetFaHapVerifyInfo failed!"); + return false; + } + } + hapVerifyInfos.push_back(hapVerifyInfo); + } + return true; +} + +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!"); + return false; + } + fs::path fsHapPath(hapPath); + std::string fileName = fsHapPath.filename().string(); + if (fileName.empty()) { + LOGE("Hap file name is empty!"); + return false; + } + std::transform(fileName.begin(), fileName.end(), fileName.begin(), ::tolower); + if (!Utils::EndsWith(fileName, HAP_SUFFIX) && !Utils::EndsWith(fileName, HSP_SUFFIX)) { + LOGE("Hap file is not a hap or hsp file!"); + return false; + } + auto hapVerifyInfo = std::make_shared(); + if (IsModuleHap(hapPath)) { + if (!GetStageHapVerifyInfo(hapPath, *hapVerifyInfo)) { + LOGE("GetStageHapVerifyInfo failed"); + return false; + } + } else { + if (!GetFaHapVerifyInfo(hapPath, *hapVerifyInfo)) { + LOGE("GetFaHapVerifyInfo failed"); + return false; + } + } + hapVerifyInfoMap.emplace(fileName, hapVerifyInfo); + } + return true; +} + +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; + } + 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; + } + + 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) { + unzClose(zipApp); + LOGE("ModuleJsonUtils::CheckAppAtomicServiceCompressedSizeValid: failed to get file info (phase 1)"); + return false; + } + + std::vector fileNameBuffer(fileInfo.size_filename + 1); + if (unzGetCurrentFileInfo(zipApp, &fileInfo, fileNameBuffer.data(), fileNameBuffer.size(), + nullptr, 0, nullptr, 0) != UNZ_OK) { + unzClose(zipApp); + LOGE("ModuleJsonUtils::CheckAppAtomicServiceCompressedSizeValid: failed to get file info (phase 2)"); + return false; + } + + std::string fileName(fileNameBuffer.data()); + auto it = hapVerifyInfoMap.find(fileName); + if (it == hapVerifyInfoMap.end() || it->second == 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; + } + return !hapVerifyInfos.front().IsStageModule(); +} + +bool ModuleJsonUtils::CheckAppAtomicServiceCompressedSizeValid( + std::map parameterMap, + std::map>& hapVerifyInfoMap) +{ + if (MockModuleJsonUtils::mockCheckAppAtomicServiceCompressedSizeValid_) { + return MockModuleJsonUtils::mockCheckAppAtomicServiceCompressedSizeValidResult_; + } + + 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); +} + +// java : checkHapIsValid +bool ModuleJsonUtils::CheckHapsIsValid(const std::list& fileList, const bool& isSharedApp) +{ + if (MockModuleJsonUtils::mockCheckHapsIsValid_) { + return MockModuleJsonUtils::mockCheckHapsIsValidResult_; + } + + std::list hapVerifyInfos; + if (!GetHapVerifyInfosfromFileList(fileList, hapVerifyInfos)) { + LOGE("GetHapVerifyInfosfromFileList failed!"); + return false; + } + if (isSharedApp) { + bool isOverlay = false; + if (!CheckSharedAppIsValid(hapVerifyInfos, isOverlay)) { + LOGE("CheckSharedAppIsValid failed!"); + return false; + } + if (!isOverlay) { + return true; + } + } else { + for (auto& hapVerifyInfo : hapVerifyInfos) { + if (hapVerifyInfo.GetBundleType().compare(TYPE_SHARED) == 0) { + LOGE("bundle type cannot be %s when app is not shared", TYPE_SHARED.c_str()); + return false; + } + } + } + setAtomicServiceFileSizeLimit(hapVerifyInfos); + if (!HapVerifyUtils::CheckHapIsValid(hapVerifyInfos)) { + LOGE("CheckHapIsValid failed!"); + return false; + } + return true; +} + +bool ModuleJsonUtils::IsModuleHap(const std::string hapFilePath) +{ + if (MockModuleJsonUtils::mockIsModuleHap_) { + return MockModuleJsonUtils::mockIsModuleHapResult_; + } + + return ZipUtils::IsFileExistsInZip(hapFilePath, MODULE_JSON); +} + +void ModuleJsonUtils::setAtomicServiceFileSizeLimit(std::list& hapVerifyInfos) +{ + for (auto& hapVerifyInfo : hapVerifyInfos) { + if (hapVerifyInfo.GetBundleType().compare(ATOMIC_SERVICE) == 0) { + hapVerifyInfo.SetEntrySizeLimit(g_entryModuleSizeLimit); + hapVerifyInfo.SetNotEntrySizeLimit(g_notEntryModuleSizeLimit); + hapVerifyInfo.SetSumSizeLimit(g_sumModuleSizeLimit); + } + } +} +} // namespace AppPackingTool +} // namespace OHOS diff --git a/packing_tool/frameworks/test/unittest/fast_app_packager_test/mock/mock_module_json_utils.h b/packing_tool/frameworks/test/unittest/fast_app_packager_test/mock/mock_module_json_utils.h new file mode 100644 index 00000000..fdb8f6f0 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/fast_app_packager_test/mock/mock_module_json_utils.h @@ -0,0 +1,116 @@ +/* + * 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. + */ + +#ifndef MOCK_MODULE_JSON_UTILS_H +#define MOCK_MODULE_JSON_UTILS_H + +#include +#include "hap_verify_info.h" + +namespace OHOS { + +using namespace OHOS::AppPackingTool; +using ResultSeries = std::vector>; + +class MockModuleJsonUtils { +public: + static bool mockGetStageHapVerifyInfo_; + static bool mockGetFaHapVerifyInfo_; + static bool mockCheckHapsIsValid_; + static bool mockIsModuleHap_; + static bool mockCheckHapsIsValidResult_; + static bool mockIsModuleHapResult_; + static bool mockCheckAppAtomicServiceCompressedSizeValid_; + static bool mockCheckAppAtomicServiceCompressedSizeValidResult_; + static bool mockGetHapVerifyInfosMapfromFileList_; + static bool mockGetHapVerifyInfosMapfromFileListResult_; + static ResultSeries mockGetStageHapVerifyInfoResultSeries_; + static ResultSeries::const_iterator mockGetStageHapVerifyInfoResultSeriesIter_; + static ResultSeries mockGetFaHapVerifyInfoResultSeries_; + static ResultSeries::const_iterator mockGetFaHapVerifyInfoResultSeriesIter_; + +public: + static void Reset() + { + mockGetStageHapVerifyInfo_ = false; + mockGetFaHapVerifyInfo_ = false; + mockCheckHapsIsValid_ = false; + mockIsModuleHap_ = false; + mockCheckHapsIsValidResult_ = false; + mockIsModuleHapResult_ = false; + mockCheckAppAtomicServiceCompressedSizeValid_ = false; + mockCheckAppAtomicServiceCompressedSizeValidResult_ = false; + mockGetHapVerifyInfosMapfromFileList_ = false; + mockGetHapVerifyInfosMapfromFileListResult_ = false; + mockGetStageHapVerifyInfoResultSeries_.clear(); + mockGetStageHapVerifyInfoResultSeriesIter_ = mockGetStageHapVerifyInfoResultSeries_.cbegin(); + mockGetFaHapVerifyInfoResultSeries_.clear(); + mockGetFaHapVerifyInfoResultSeriesIter_ = mockGetStageHapVerifyInfoResultSeries_.cbegin(); + } + + static void MockGetStageHapVerifyInfo(const ResultSeries& resultSeries) + { + mockGetStageHapVerifyInfo_ = true; + mockGetStageHapVerifyInfoResultSeries_ = resultSeries; + mockGetStageHapVerifyInfoResultSeriesIter_ = mockGetStageHapVerifyInfoResultSeries_.cbegin(); + } + + static void MockGetStageHapVerifyInfo(const bool result, const HapVerifyInfo& hapVerifyInfo) + { + ResultSeries series; + series.emplace_back(result, hapVerifyInfo); + MockGetStageHapVerifyInfo(series); + } + + static void MockGetFaHapVerifyInfo(const ResultSeries& resultSeries) + { + mockGetFaHapVerifyInfo_ = true; + mockGetFaHapVerifyInfoResultSeries_ = resultSeries; + mockGetFaHapVerifyInfoResultSeriesIter_ = mockGetStageHapVerifyInfoResultSeries_.cbegin(); + } + + static void MockGetFaHapVerifyInfo(const bool result, const HapVerifyInfo& hapVerifyInfo) + { + ResultSeries series; + series.emplace_back(result, hapVerifyInfo); + MockGetFaHapVerifyInfo(series); + } + + static void MockCheckHapsIsValid(const bool result) + { + mockCheckHapsIsValid_ = true; + mockCheckHapsIsValidResult_ = result; + } + + static void MockIsModuleHap(const bool result) + { + mockIsModuleHap_ = true; + mockIsModuleHapResult_ = result; + } + + static void MockCheckAppAtomicServiceCompressedSizeValid(const bool result) + { + mockCheckAppAtomicServiceCompressedSizeValid_ = true; + mockCheckAppAtomicServiceCompressedSizeValidResult_ = result; + } + + static void MockGetHapVerifyInfosMapfromFileList(const bool result) + { + mockGetHapVerifyInfosMapfromFileList_ = true; + mockGetHapVerifyInfosMapfromFileListResult_ = result; + } +}; +} // namespace OHOS +#endif // MOCK_MODULE_JSON_UTILS_H \ No newline at end of file diff --git a/packing_tool/frameworks/test/unittest/multiapp_packager_test/BUILD.gn b/packing_tool/frameworks/test/unittest/multiapp_packager_test/BUILD.gn index 2d72c706..955e916f 100644 --- a/packing_tool/frameworks/test/unittest/multiapp_packager_test/BUILD.gn +++ b/packing_tool/frameworks/test/unittest/multiapp_packager_test/BUILD.gn @@ -48,6 +48,7 @@ ohos_unittest("multiapp_packager_test") { "../../../src/zip_utils.cpp", "../../../src/zip_wrapper.cpp", "multiapp_packager_test.cpp", + "mock/mock_module_json_utils.cpp", ] external_deps = [ "bounds_checking_function:libsec_static", diff --git a/packing_tool/frameworks/test/unittest/multiapp_packager_test/mock/mock_module_json_utils.cpp b/packing_tool/frameworks/test/unittest/multiapp_packager_test/mock/mock_module_json_utils.cpp new file mode 100644 index 00000000..4c800e65 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/multiapp_packager_test/mock/mock_module_json_utils.cpp @@ -0,0 +1,407 @@ +/* + * 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 "module_json_utils.h" + +#include +#include +#include + +#include "hap_verify_utils.h" +#include "log.h" +#include "mock_module_json_utils.h" +#include "module_json.h" +#include "utils.h" +#include "zip_utils.h" +#include "constants.h" + +namespace fs = std::filesystem; + +namespace OHOS { + +bool MockModuleJsonUtils::mockGetStageHapVerifyInfo_ = false; +bool MockModuleJsonUtils::mockGetFaHapVerifyInfo_ = false; +bool MockModuleJsonUtils::mockCheckHapsIsValid_ = false; +bool MockModuleJsonUtils::mockIsModuleHap_ = false; +bool MockModuleJsonUtils::mockCheckHapsIsValidResult_ = false; +bool MockModuleJsonUtils::mockIsModuleHapResult_ = false; +bool MockModuleJsonUtils::mockCheckAppAtomicServiceCompressedSizeValid_ = false; +bool MockModuleJsonUtils::mockCheckAppAtomicServiceCompressedSizeValidResult_ = false; +bool MockModuleJsonUtils::mockGetHapVerifyInfosMapfromFileList_ = false; +bool MockModuleJsonUtils::mockGetHapVerifyInfosMapfromFileListResult_ = false; +ResultSeries MockModuleJsonUtils::mockGetStageHapVerifyInfoResultSeries_; +ResultSeries::const_iterator + MockModuleJsonUtils::mockGetStageHapVerifyInfoResultSeriesIter_ = mockGetStageHapVerifyInfoResultSeries_.cbegin(); +ResultSeries MockModuleJsonUtils::mockGetFaHapVerifyInfoResultSeries_; +ResultSeries::const_iterator + MockModuleJsonUtils::mockGetFaHapVerifyInfoResultSeriesIter_ = mockGetFaHapVerifyInfoResultSeries_.cbegin(); + +namespace AppPackingTool { +namespace { +const std::string MODULE_JSON = "module.json"; +const std::string CONFIG_JSON = "config.json"; +const std::string HAP_SUFFIX = ".hap"; +const std::string HSP_SUFFIX = ".hsp"; +const int32_t SHARED_APP_HSP_LIMIT = 1; +const std::string TYPE_SHARED = "shared"; +const std::string INCLUDE = "include"; +const std::string EXCLUDE = "exclude"; +const std::string ATOMIC_SERVICE = "atomicService"; +static int32_t g_entryModuleSizeLimit = 2; +static int32_t g_notEntryModuleSizeLimit = 2; +static int32_t g_sumModuleSizeLimit = 10; +} + +// java : parseStageHapVerifyInfo +bool ModuleJsonUtils::GetStageHapVerifyInfo(const std::string& hapFilePath, HapVerifyInfo& hapVerifyInfo) +{ + if (MockModuleJsonUtils::mockGetStageHapVerifyInfo_) { + const bool result = MockModuleJsonUtils::mockGetStageHapVerifyInfoResultSeriesIter_->first; + hapVerifyInfo = MockModuleJsonUtils::mockGetStageHapVerifyInfoResultSeriesIter_->second; + + const auto next = MockModuleJsonUtils::mockGetStageHapVerifyInfoResultSeriesIter_ + 1; + if (next != MockModuleJsonUtils::mockGetStageHapVerifyInfoResultSeries_.cend()) { + MockModuleJsonUtils::mockGetStageHapVerifyInfoResultSeriesIter_ = next; + } + + return result; + } + + std::string fileContent; + std::map resourceMap; + int64_t fileLength = Utils::GetFileLength(hapFilePath); + if (fileLength < 0) { + LOGE("Get hap file length failed! hapFile=%s", hapFilePath.c_str()); + return false; + } + if (!ZipUtils::GetFileContentFromZip(hapFilePath, MODULE_JSON, fileContent)) { + LOGE("Get module.json content from hap file failed! hapFile=%s", hapFilePath.c_str()); + return false; + } + if (!ZipUtils::GetResourceMapFromZip(hapFilePath, resourceMap)) { + LOGE("Get resouce map from hap file failed! hapFile=%s", hapFilePath.c_str()); + return false; + } + hapVerifyInfo.SetResourceMap(resourceMap); + hapVerifyInfo.SetProfileStr(fileContent); + hapVerifyInfo.SetStageModule(true); + hapVerifyInfo.SetFileLength(fileLength); + ModuleJson moduleJson; + if (!moduleJson.ParseFromString(fileContent)) { + LOGE("Parse json string failed!"); + return false; + } + if (!moduleJson.GetStageHapVerifyInfo(hapVerifyInfo)) { + LOGE("Get stage hap verify info failed!"); + return false; + } + return true; +} + +bool ModuleJsonUtils::GetFaHapVerifyInfo(const std::string& hapFilePath, HapVerifyInfo& hapVerifyInfo) +{ + if (MockModuleJsonUtils::mockGetFaHapVerifyInfo_) { + const bool result = MockModuleJsonUtils::mockGetFaHapVerifyInfoResultSeriesIter_->first; + hapVerifyInfo = MockModuleJsonUtils::mockGetFaHapVerifyInfoResultSeriesIter_->second; + + const auto next = MockModuleJsonUtils::mockGetFaHapVerifyInfoResultSeriesIter_ + 1; + if (next != MockModuleJsonUtils::mockGetFaHapVerifyInfoResultSeries_.cend()) { + MockModuleJsonUtils::mockGetFaHapVerifyInfoResultSeriesIter_ = next; + } + + return result; + } + + std::string fileContent; + int64_t fileLength = Utils::GetFileLength(hapFilePath); + if (fileLength < 0) { + LOGE("Get hap file length failed! hapFile=%s", hapFilePath.c_str()); + return false; + } + if (!ZipUtils::GetFileContentFromZip(hapFilePath, CONFIG_JSON, fileContent)) { + LOGE("Get module.json content from hap file failed! hapFile=%s", hapFilePath.c_str()); + return false; + } + ModuleJson moduleJson; + if (!moduleJson.ParseFromString(fileContent)) { + LOGE("Parse json string failed!"); + return false; + } + if (!moduleJson.GetFaHapVerifyInfo(hapVerifyInfo)) { + LOGE("Get FA hap verify info failed!"); + return false; + } + hapVerifyInfo.SetProfileStr(fileContent); + hapVerifyInfo.SetStageModule(false); + hapVerifyInfo.SetFileLength(fileLength); + return true; +} + +// java : Compressor::checkSharedAppIsValid / HapVerify::checkSharedApppIsValid +bool ModuleJsonUtils::CheckSharedAppIsValid(const std::list& hapVerifyInfos, bool& isOverlay) +{ + if (hapVerifyInfos.empty()) { + LOGE("hapVerifyInfos is empty"); + return false; + } + if (hapVerifyInfos.size() > SHARED_APP_HSP_LIMIT) { + LOGE("hapVerifyInfos size is over than %d", SHARED_APP_HSP_LIMIT); + return false; + } + for (auto& hapVerifyInfo : hapVerifyInfos) { + if (!hapVerifyInfo.GetTargetBundleName().empty()) { + isOverlay = true; + return true; + } + } + return HapVerifyUtils::CheckSharedAppIsValid(hapVerifyInfos); +} + +bool ModuleJsonUtils::GetHapVerifyInfosfromFileList(const std::list& fileList, + std::list& hapVerifyInfos) +{ + for (auto& hapPath : fileList) { + if (hapPath.empty()) { + LOGE("Hap file path is empty!"); + return false; + } + fs::path fsHapPath(hapPath); + std::string fileName = fsHapPath.filename().string(); + if (fileName.empty()) { + LOGE("Hap file name is empty!"); + return false; + } + std::transform(fileName.begin(), fileName.end(), fileName.begin(), ::tolower); + if (!Utils::EndsWith(fileName, HAP_SUFFIX) && !Utils::EndsWith(fileName, HSP_SUFFIX)) { + LOGE("Hap file is not a hap or hsp file!"); + return false; + } + HapVerifyInfo hapVerifyInfo; + if (IsModuleHap(hapPath)) { + if (!GetStageHapVerifyInfo(hapPath, hapVerifyInfo)) { + LOGE("GetStageHapVerifyInfo failed!"); + return false; + } + } else { + if (!GetFaHapVerifyInfo(hapPath, hapVerifyInfo)) { + LOGE("GetFaHapVerifyInfo failed!"); + return false; + } + } + hapVerifyInfos.push_back(hapVerifyInfo); + } + return true; +} + +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!"); + return false; + } + fs::path fsHapPath(hapPath); + std::string fileName = fsHapPath.filename().string(); + if (fileName.empty()) { + LOGE("Hap file name is empty!"); + return false; + } + std::transform(fileName.begin(), fileName.end(), fileName.begin(), ::tolower); + if (!Utils::EndsWith(fileName, HAP_SUFFIX) && !Utils::EndsWith(fileName, HSP_SUFFIX)) { + LOGE("Hap file is not a hap or hsp file!"); + return false; + } + auto hapVerifyInfo = std::make_shared(); + if (IsModuleHap(hapPath)) { + if (!GetStageHapVerifyInfo(hapPath, *hapVerifyInfo)) { + LOGE("GetStageHapVerifyInfo failed"); + return false; + } + } else { + if (!GetFaHapVerifyInfo(hapPath, *hapVerifyInfo)) { + LOGE("GetFaHapVerifyInfo failed"); + return false; + } + } + hapVerifyInfoMap.emplace(fileName, hapVerifyInfo); + } + return true; +} + +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; + } + 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; + } + + 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) { + unzClose(zipApp); + LOGE("ModuleJsonUtils::CheckAppAtomicServiceCompressedSizeValid: failed to get file info (phase 1)"); + return false; + } + + std::vector fileNameBuffer(fileInfo.size_filename + 1); + if (unzGetCurrentFileInfo(zipApp, &fileInfo, fileNameBuffer.data(), fileNameBuffer.size(), + nullptr, 0, nullptr, 0) != UNZ_OK) { + unzClose(zipApp); + LOGE("ModuleJsonUtils::CheckAppAtomicServiceCompressedSizeValid: failed to get file info (phase 2)"); + return false; + } + + std::string fileName(fileNameBuffer.data()); + auto it = hapVerifyInfoMap.find(fileName); + if (it == hapVerifyInfoMap.end() || it->second == 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; + } + return !hapVerifyInfos.front().IsStageModule(); +} + +bool ModuleJsonUtils::CheckAppAtomicServiceCompressedSizeValid( + std::map parameterMap, + std::map>& hapVerifyInfoMap) +{ + if (MockModuleJsonUtils::mockCheckAppAtomicServiceCompressedSizeValid_) { + return MockModuleJsonUtils::mockCheckAppAtomicServiceCompressedSizeValidResult_; + } + + 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); +} + +// java : checkHapIsValid +bool ModuleJsonUtils::CheckHapsIsValid(const std::list& fileList, const bool& isSharedApp) +{ + if (MockModuleJsonUtils::mockCheckHapsIsValid_) { + return MockModuleJsonUtils::mockCheckHapsIsValidResult_; + } + + std::list hapVerifyInfos; + if (!GetHapVerifyInfosfromFileList(fileList, hapVerifyInfos)) { + LOGE("GetHapVerifyInfosfromFileList failed!"); + return false; + } + if (isSharedApp) { + bool isOverlay = false; + if (!CheckSharedAppIsValid(hapVerifyInfos, isOverlay)) { + LOGE("CheckSharedAppIsValid failed!"); + return false; + } + if (!isOverlay) { + return true; + } + } else { + for (auto& hapVerifyInfo : hapVerifyInfos) { + if (hapVerifyInfo.GetBundleType().compare(TYPE_SHARED) == 0) { + LOGE("bundle type cannot be %s when app is not shared", TYPE_SHARED.c_str()); + return false; + } + } + } + setAtomicServiceFileSizeLimit(hapVerifyInfos); + if (!HapVerifyUtils::CheckHapIsValid(hapVerifyInfos)) { + LOGE("CheckHapIsValid failed!"); + return false; + } + return true; +} + +bool ModuleJsonUtils::IsModuleHap(const std::string hapFilePath) +{ + if (MockModuleJsonUtils::mockIsModuleHap_) { + return MockModuleJsonUtils::mockIsModuleHapResult_; + } + + return ZipUtils::IsFileExistsInZip(hapFilePath, MODULE_JSON); +} + +void ModuleJsonUtils::setAtomicServiceFileSizeLimit(std::list& hapVerifyInfos) +{ + for (auto& hapVerifyInfo : hapVerifyInfos) { + if (hapVerifyInfo.GetBundleType().compare(ATOMIC_SERVICE) == 0) { + hapVerifyInfo.SetEntrySizeLimit(g_entryModuleSizeLimit); + hapVerifyInfo.SetNotEntrySizeLimit(g_notEntryModuleSizeLimit); + hapVerifyInfo.SetSumSizeLimit(g_sumModuleSizeLimit); + } + } +} +} // namespace AppPackingTool +} // namespace OHOS diff --git a/packing_tool/frameworks/test/unittest/multiapp_packager_test/mock/mock_module_json_utils.h b/packing_tool/frameworks/test/unittest/multiapp_packager_test/mock/mock_module_json_utils.h new file mode 100644 index 00000000..fdb8f6f0 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/multiapp_packager_test/mock/mock_module_json_utils.h @@ -0,0 +1,116 @@ +/* + * 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. + */ + +#ifndef MOCK_MODULE_JSON_UTILS_H +#define MOCK_MODULE_JSON_UTILS_H + +#include +#include "hap_verify_info.h" + +namespace OHOS { + +using namespace OHOS::AppPackingTool; +using ResultSeries = std::vector>; + +class MockModuleJsonUtils { +public: + static bool mockGetStageHapVerifyInfo_; + static bool mockGetFaHapVerifyInfo_; + static bool mockCheckHapsIsValid_; + static bool mockIsModuleHap_; + static bool mockCheckHapsIsValidResult_; + static bool mockIsModuleHapResult_; + static bool mockCheckAppAtomicServiceCompressedSizeValid_; + static bool mockCheckAppAtomicServiceCompressedSizeValidResult_; + static bool mockGetHapVerifyInfosMapfromFileList_; + static bool mockGetHapVerifyInfosMapfromFileListResult_; + static ResultSeries mockGetStageHapVerifyInfoResultSeries_; + static ResultSeries::const_iterator mockGetStageHapVerifyInfoResultSeriesIter_; + static ResultSeries mockGetFaHapVerifyInfoResultSeries_; + static ResultSeries::const_iterator mockGetFaHapVerifyInfoResultSeriesIter_; + +public: + static void Reset() + { + mockGetStageHapVerifyInfo_ = false; + mockGetFaHapVerifyInfo_ = false; + mockCheckHapsIsValid_ = false; + mockIsModuleHap_ = false; + mockCheckHapsIsValidResult_ = false; + mockIsModuleHapResult_ = false; + mockCheckAppAtomicServiceCompressedSizeValid_ = false; + mockCheckAppAtomicServiceCompressedSizeValidResult_ = false; + mockGetHapVerifyInfosMapfromFileList_ = false; + mockGetHapVerifyInfosMapfromFileListResult_ = false; + mockGetStageHapVerifyInfoResultSeries_.clear(); + mockGetStageHapVerifyInfoResultSeriesIter_ = mockGetStageHapVerifyInfoResultSeries_.cbegin(); + mockGetFaHapVerifyInfoResultSeries_.clear(); + mockGetFaHapVerifyInfoResultSeriesIter_ = mockGetStageHapVerifyInfoResultSeries_.cbegin(); + } + + static void MockGetStageHapVerifyInfo(const ResultSeries& resultSeries) + { + mockGetStageHapVerifyInfo_ = true; + mockGetStageHapVerifyInfoResultSeries_ = resultSeries; + mockGetStageHapVerifyInfoResultSeriesIter_ = mockGetStageHapVerifyInfoResultSeries_.cbegin(); + } + + static void MockGetStageHapVerifyInfo(const bool result, const HapVerifyInfo& hapVerifyInfo) + { + ResultSeries series; + series.emplace_back(result, hapVerifyInfo); + MockGetStageHapVerifyInfo(series); + } + + static void MockGetFaHapVerifyInfo(const ResultSeries& resultSeries) + { + mockGetFaHapVerifyInfo_ = true; + mockGetFaHapVerifyInfoResultSeries_ = resultSeries; + mockGetFaHapVerifyInfoResultSeriesIter_ = mockGetStageHapVerifyInfoResultSeries_.cbegin(); + } + + static void MockGetFaHapVerifyInfo(const bool result, const HapVerifyInfo& hapVerifyInfo) + { + ResultSeries series; + series.emplace_back(result, hapVerifyInfo); + MockGetFaHapVerifyInfo(series); + } + + static void MockCheckHapsIsValid(const bool result) + { + mockCheckHapsIsValid_ = true; + mockCheckHapsIsValidResult_ = result; + } + + static void MockIsModuleHap(const bool result) + { + mockIsModuleHap_ = true; + mockIsModuleHapResult_ = result; + } + + static void MockCheckAppAtomicServiceCompressedSizeValid(const bool result) + { + mockCheckAppAtomicServiceCompressedSizeValid_ = true; + mockCheckAppAtomicServiceCompressedSizeValidResult_ = result; + } + + static void MockGetHapVerifyInfosMapfromFileList(const bool result) + { + mockGetHapVerifyInfosMapfromFileList_ = true; + mockGetHapVerifyInfosMapfromFileListResult_ = result; + } +}; +} // namespace OHOS +#endif // MOCK_MODULE_JSON_UTILS_H \ No newline at end of file diff --git a/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiapp_packager_test.cpp b/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiapp_packager_test.cpp index 6e5053ed..4b8f115e 100644 --- a/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiapp_packager_test.cpp +++ b/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiapp_packager_test.cpp @@ -22,6 +22,7 @@ #define protected public #include "packager.h" #include "multiapp_packager.h" +#include "mock/mock_module_json_utils.h" #include "zip_wrapper.h" #include "zip_utils.h" #include "log.h" @@ -107,6 +108,8 @@ HWTEST_F(MultiAppPackagerTest, MultiAppPackager_0100, Function | MediumTest | Le }; OHOS::AppPackingTool::MultiAppPackager multiAppPackager(parameterMap, resultReceiver); + MockModuleJsonUtils::MockCheckAppAtomicServiceCompressedSizeValid(true); + MockModuleJsonUtils::MockGetHapVerifyInfosMapfromFileList(true); EXPECT_EQ(multiAppPackager.InitAllowedParam(), 0); EXPECT_EQ(multiAppPackager.PreProcess(), 0); EXPECT_EQ(multiAppPackager.Process(), 0); @@ -300,6 +303,8 @@ HWTEST_F(MultiAppPackagerTest, PreProcess_1000, Function | MediumTest | Level1) }; OHOS::AppPackingTool::MultiAppPackager multiAppPackager(parameterMap, resultReceiver); + MockModuleJsonUtils::MockCheckAppAtomicServiceCompressedSizeValid(true); + MockModuleJsonUtils::MockGetHapVerifyInfosMapfromFileList(true); EXPECT_EQ(multiAppPackager.PreProcess(), 1); } @@ -381,6 +386,8 @@ HWTEST_F(MultiAppPackagerTest, PreProcess_1400, Function | MediumTest | Level1) }; OHOS::AppPackingTool::MultiAppPackager multiAppPackager(parameterMap, resultReceiver); + MockModuleJsonUtils::MockCheckAppAtomicServiceCompressedSizeValid(true); + MockModuleJsonUtils::MockGetHapVerifyInfosMapfromFileList(true); EXPECT_EQ(multiAppPackager.PreProcess(), 1); EXPECT_EQ(multiAppPackager.CompressAppModeForMultiProject(), true); } @@ -425,6 +432,8 @@ HWTEST_F(MultiAppPackagerTest, PreProcess_1600, Function | MediumTest | Level1) }; OHOS::AppPackingTool::MultiAppPackager multiAppPackager(parameterMap, resultReceiver); + MockModuleJsonUtils::MockCheckAppAtomicServiceCompressedSizeValid(true); + MockModuleJsonUtils::MockGetHapVerifyInfosMapfromFileList(true); EXPECT_EQ(multiAppPackager.PreProcess(), 1); EXPECT_EQ(multiAppPackager.CompressAppModeForMultiProject(), true); } -- Gitee From 2b6e07042bacdc1277ec68cf84bfbcbc8312be3e Mon Sep 17 00:00:00 2001 From: z30034863 Date: Thu, 5 Jun 2025 21:31:26 +0800 Subject: [PATCH 09/15] fix tdd 7 Signed-off-by: z30034863 --- .../test/unittest/fast_app_packager_test/BUILD.gn | 2 +- .../fast_app_packager_test/fast_app_packager_test.cpp | 2 +- ..._json_utils.cpp => mock_fastapp_module_json_utils.cpp} | 6 +++--- ...dule_json_utils.h => mock_fastapp_module_json_utils.h} | 8 ++++---- .../test/unittest/multiapp_packager_test/BUILD.gn | 2 +- ...json_utils.cpp => mock_multiapp_module_json_utils.cpp} | 6 +++--- ...ule_json_utils.h => mock_multiapp_module_json_utils.h} | 8 ++++---- 7 files changed, 17 insertions(+), 17 deletions(-) rename packing_tool/frameworks/test/unittest/fast_app_packager_test/mock/{mock_module_json_utils.cpp => mock_fastapp_module_json_utils.cpp} (99%) rename packing_tool/frameworks/test/unittest/fast_app_packager_test/mock/{mock_module_json_utils.h => mock_fastapp_module_json_utils.h} (96%) rename packing_tool/frameworks/test/unittest/multiapp_packager_test/mock/{mock_module_json_utils.cpp => mock_multiapp_module_json_utils.cpp} (99%) rename packing_tool/frameworks/test/unittest/multiapp_packager_test/mock/{mock_module_json_utils.h => mock_multiapp_module_json_utils.h} (96%) diff --git a/packing_tool/frameworks/test/unittest/fast_app_packager_test/BUILD.gn b/packing_tool/frameworks/test/unittest/fast_app_packager_test/BUILD.gn index 00d65bbe..85012e37 100644 --- a/packing_tool/frameworks/test/unittest/fast_app_packager_test/BUILD.gn +++ b/packing_tool/frameworks/test/unittest/fast_app_packager_test/BUILD.gn @@ -47,7 +47,7 @@ ohos_unittest("fast_app_packager_test") { "../../../src/zip_utils.cpp", "../../../src/zip_wrapper.cpp", "fast_app_packager_test.cpp", - "mock/mock_module_json_utils.cpp", + "mock/mock_fastapp_module_json_utils.cpp", ] external_deps = [ "bounds_checking_function:libsec_static", diff --git a/packing_tool/frameworks/test/unittest/fast_app_packager_test/fast_app_packager_test.cpp b/packing_tool/frameworks/test/unittest/fast_app_packager_test/fast_app_packager_test.cpp index aac39e0a..9baa7759 100644 --- a/packing_tool/frameworks/test/unittest/fast_app_packager_test/fast_app_packager_test.cpp +++ b/packing_tool/frameworks/test/unittest/fast_app_packager_test/fast_app_packager_test.cpp @@ -21,7 +21,7 @@ #define private public #define protected public #include "fast_app_packager.h" -#include "mock/mock_module_json_utils.h" +#include "mock/mock_fastapp_module_json_utils.h" #undef private #undef protected diff --git a/packing_tool/frameworks/test/unittest/fast_app_packager_test/mock/mock_module_json_utils.cpp b/packing_tool/frameworks/test/unittest/fast_app_packager_test/mock/mock_fastapp_module_json_utils.cpp similarity index 99% rename from packing_tool/frameworks/test/unittest/fast_app_packager_test/mock/mock_module_json_utils.cpp rename to packing_tool/frameworks/test/unittest/fast_app_packager_test/mock/mock_fastapp_module_json_utils.cpp index 4c800e65..db9102d4 100644 --- a/packing_tool/frameworks/test/unittest/fast_app_packager_test/mock/mock_module_json_utils.cpp +++ b/packing_tool/frameworks/test/unittest/fast_app_packager_test/mock/mock_fastapp_module_json_utils.cpp @@ -21,7 +21,7 @@ #include "hap_verify_utils.h" #include "log.h" -#include "mock_module_json_utils.h" +#include "mock_fastapp_module_json_utils.h" #include "module_json.h" #include "utils.h" #include "zip_utils.h" @@ -48,7 +48,7 @@ ResultSeries MockModuleJsonUtils::mockGetFaHapVerifyInfoResultSeries_; ResultSeries::const_iterator MockModuleJsonUtils::mockGetFaHapVerifyInfoResultSeriesIter_ = mockGetFaHapVerifyInfoResultSeries_.cbegin(); -namespace AppPackingTool { +namespace FastAppPackingTool { namespace { const std::string MODULE_JSON = "module.json"; const std::string CONFIG_JSON = "config.json"; @@ -403,5 +403,5 @@ void ModuleJsonUtils::setAtomicServiceFileSizeLimit(std::list& ha } } } -} // namespace AppPackingTool +} // namespace FastAppPackingTool } // namespace OHOS diff --git a/packing_tool/frameworks/test/unittest/fast_app_packager_test/mock/mock_module_json_utils.h b/packing_tool/frameworks/test/unittest/fast_app_packager_test/mock/mock_fastapp_module_json_utils.h similarity index 96% rename from packing_tool/frameworks/test/unittest/fast_app_packager_test/mock/mock_module_json_utils.h rename to packing_tool/frameworks/test/unittest/fast_app_packager_test/mock/mock_fastapp_module_json_utils.h index fdb8f6f0..86642df3 100644 --- a/packing_tool/frameworks/test/unittest/fast_app_packager_test/mock/mock_module_json_utils.h +++ b/packing_tool/frameworks/test/unittest/fast_app_packager_test/mock/mock_fastapp_module_json_utils.h @@ -13,15 +13,15 @@ * limitations under the License. */ -#ifndef MOCK_MODULE_JSON_UTILS_H -#define MOCK_MODULE_JSON_UTILS_H +#ifndef MOCK_FASTAPP_MODULE_JSON_UTILS_H +#define MOCK_FASTAPP_MODULE_JSON_UTILS_H #include #include "hap_verify_info.h" namespace OHOS { -using namespace OHOS::AppPackingTool; +using namespace OHOS::FastAppPackingTool; using ResultSeries = std::vector>; class MockModuleJsonUtils { @@ -113,4 +113,4 @@ public: } }; } // namespace OHOS -#endif // MOCK_MODULE_JSON_UTILS_H \ No newline at end of file +#endif // MOCK_FASTAPP_MODULE_JSON_UTILS_H \ No newline at end of file diff --git a/packing_tool/frameworks/test/unittest/multiapp_packager_test/BUILD.gn b/packing_tool/frameworks/test/unittest/multiapp_packager_test/BUILD.gn index 955e916f..3c8fd469 100644 --- a/packing_tool/frameworks/test/unittest/multiapp_packager_test/BUILD.gn +++ b/packing_tool/frameworks/test/unittest/multiapp_packager_test/BUILD.gn @@ -48,7 +48,7 @@ ohos_unittest("multiapp_packager_test") { "../../../src/zip_utils.cpp", "../../../src/zip_wrapper.cpp", "multiapp_packager_test.cpp", - "mock/mock_module_json_utils.cpp", + "mock/mock_multiapp_module_json_utils.cpp", ] external_deps = [ "bounds_checking_function:libsec_static", diff --git a/packing_tool/frameworks/test/unittest/multiapp_packager_test/mock/mock_module_json_utils.cpp b/packing_tool/frameworks/test/unittest/multiapp_packager_test/mock/mock_multiapp_module_json_utils.cpp similarity index 99% rename from packing_tool/frameworks/test/unittest/multiapp_packager_test/mock/mock_module_json_utils.cpp rename to packing_tool/frameworks/test/unittest/multiapp_packager_test/mock/mock_multiapp_module_json_utils.cpp index 4c800e65..183637fb 100644 --- a/packing_tool/frameworks/test/unittest/multiapp_packager_test/mock/mock_module_json_utils.cpp +++ b/packing_tool/frameworks/test/unittest/multiapp_packager_test/mock/mock_multiapp_module_json_utils.cpp @@ -21,7 +21,7 @@ #include "hap_verify_utils.h" #include "log.h" -#include "mock_module_json_utils.h" +#include "mock_multiapp_module_json_utils.h" #include "module_json.h" #include "utils.h" #include "zip_utils.h" @@ -48,7 +48,7 @@ ResultSeries MockModuleJsonUtils::mockGetFaHapVerifyInfoResultSeries_; ResultSeries::const_iterator MockModuleJsonUtils::mockGetFaHapVerifyInfoResultSeriesIter_ = mockGetFaHapVerifyInfoResultSeries_.cbegin(); -namespace AppPackingTool { +namespace MultiAppPackingTool { namespace { const std::string MODULE_JSON = "module.json"; const std::string CONFIG_JSON = "config.json"; @@ -403,5 +403,5 @@ void ModuleJsonUtils::setAtomicServiceFileSizeLimit(std::list& ha } } } -} // namespace AppPackingTool +} // namespace MultiAppPackingTool } // namespace OHOS diff --git a/packing_tool/frameworks/test/unittest/multiapp_packager_test/mock/mock_module_json_utils.h b/packing_tool/frameworks/test/unittest/multiapp_packager_test/mock/mock_multiapp_module_json_utils.h similarity index 96% rename from packing_tool/frameworks/test/unittest/multiapp_packager_test/mock/mock_module_json_utils.h rename to packing_tool/frameworks/test/unittest/multiapp_packager_test/mock/mock_multiapp_module_json_utils.h index fdb8f6f0..915fae13 100644 --- a/packing_tool/frameworks/test/unittest/multiapp_packager_test/mock/mock_module_json_utils.h +++ b/packing_tool/frameworks/test/unittest/multiapp_packager_test/mock/mock_multiapp_module_json_utils.h @@ -13,15 +13,15 @@ * limitations under the License. */ -#ifndef MOCK_MODULE_JSON_UTILS_H -#define MOCK_MODULE_JSON_UTILS_H +#ifndef MOCK_MULTIAPP_MODULE_JSON_UTILS_H +#define MOCK_MULTIAPP_MODULE_JSON_UTILS_H #include #include "hap_verify_info.h" namespace OHOS { -using namespace OHOS::AppPackingTool; +using namespace OHOS::MultiAppPackingTool; using ResultSeries = std::vector>; class MockModuleJsonUtils { @@ -113,4 +113,4 @@ public: } }; } // namespace OHOS -#endif // MOCK_MODULE_JSON_UTILS_H \ No newline at end of file +#endif // MOCK_MULTIAPP_MODULE_JSON_UTILS_H \ No newline at end of file -- Gitee From 3f13c682bcf1caaba109ca5bdfd44fe592f45d6b Mon Sep 17 00:00:00 2001 From: zhangfengzhuang Date: Fri, 6 Jun 2025 00:44:22 +0800 Subject: [PATCH 10/15] fix tdd 8 Signed-off-by: zhangfengzhuang --- .../mock/mock_fastapp_module_json_utils.cpp | 4 ++-- .../mock/mock_fastapp_module_json_utils.h | 2 +- .../mock/mock_multiapp_module_json_utils.cpp | 4 ++-- .../mock/mock_multiapp_module_json_utils.h | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packing_tool/frameworks/test/unittest/fast_app_packager_test/mock/mock_fastapp_module_json_utils.cpp b/packing_tool/frameworks/test/unittest/fast_app_packager_test/mock/mock_fastapp_module_json_utils.cpp index db9102d4..684287b9 100644 --- a/packing_tool/frameworks/test/unittest/fast_app_packager_test/mock/mock_fastapp_module_json_utils.cpp +++ b/packing_tool/frameworks/test/unittest/fast_app_packager_test/mock/mock_fastapp_module_json_utils.cpp @@ -48,7 +48,7 @@ ResultSeries MockModuleJsonUtils::mockGetFaHapVerifyInfoResultSeries_; ResultSeries::const_iterator MockModuleJsonUtils::mockGetFaHapVerifyInfoResultSeriesIter_ = mockGetFaHapVerifyInfoResultSeries_.cbegin(); -namespace FastAppPackingTool { +namespace AppPackingTool { namespace { const std::string MODULE_JSON = "module.json"; const std::string CONFIG_JSON = "config.json"; @@ -403,5 +403,5 @@ void ModuleJsonUtils::setAtomicServiceFileSizeLimit(std::list& ha } } } -} // namespace FastAppPackingTool +} // namespace AppPackingTool } // namespace OHOS diff --git a/packing_tool/frameworks/test/unittest/fast_app_packager_test/mock/mock_fastapp_module_json_utils.h b/packing_tool/frameworks/test/unittest/fast_app_packager_test/mock/mock_fastapp_module_json_utils.h index 86642df3..4fef73b4 100644 --- a/packing_tool/frameworks/test/unittest/fast_app_packager_test/mock/mock_fastapp_module_json_utils.h +++ b/packing_tool/frameworks/test/unittest/fast_app_packager_test/mock/mock_fastapp_module_json_utils.h @@ -21,7 +21,7 @@ namespace OHOS { -using namespace OHOS::FastAppPackingTool; +using namespace OHOS::AppPackingTool; using ResultSeries = std::vector>; class MockModuleJsonUtils { diff --git a/packing_tool/frameworks/test/unittest/multiapp_packager_test/mock/mock_multiapp_module_json_utils.cpp b/packing_tool/frameworks/test/unittest/multiapp_packager_test/mock/mock_multiapp_module_json_utils.cpp index 183637fb..8bcf1b9c 100644 --- a/packing_tool/frameworks/test/unittest/multiapp_packager_test/mock/mock_multiapp_module_json_utils.cpp +++ b/packing_tool/frameworks/test/unittest/multiapp_packager_test/mock/mock_multiapp_module_json_utils.cpp @@ -48,7 +48,7 @@ ResultSeries MockModuleJsonUtils::mockGetFaHapVerifyInfoResultSeries_; ResultSeries::const_iterator MockModuleJsonUtils::mockGetFaHapVerifyInfoResultSeriesIter_ = mockGetFaHapVerifyInfoResultSeries_.cbegin(); -namespace MultiAppPackingTool { +namespace AppPackingTool { namespace { const std::string MODULE_JSON = "module.json"; const std::string CONFIG_JSON = "config.json"; @@ -403,5 +403,5 @@ void ModuleJsonUtils::setAtomicServiceFileSizeLimit(std::list& ha } } } -} // namespace MultiAppPackingTool +} // namespace AppPackingTool } // namespace OHOS diff --git a/packing_tool/frameworks/test/unittest/multiapp_packager_test/mock/mock_multiapp_module_json_utils.h b/packing_tool/frameworks/test/unittest/multiapp_packager_test/mock/mock_multiapp_module_json_utils.h index 915fae13..446feb11 100644 --- a/packing_tool/frameworks/test/unittest/multiapp_packager_test/mock/mock_multiapp_module_json_utils.h +++ b/packing_tool/frameworks/test/unittest/multiapp_packager_test/mock/mock_multiapp_module_json_utils.h @@ -21,7 +21,7 @@ namespace OHOS { -using namespace OHOS::MultiAppPackingTool; +using namespace OHOS::AppPackingTool; using ResultSeries = std::vector>; class MockModuleJsonUtils { -- Gitee From fcad583a88208ca0da0c522870bf8264061ead93 Mon Sep 17 00:00:00 2001 From: zhangfengzhuang Date: Fri, 6 Jun 2025 01:00:26 +0800 Subject: [PATCH 11/15] fix tdd 9 Signed-off-by: zhangfengzhuang --- .../fast_app_packager_test/fast_app_packager_test.cpp | 2 +- ...e_json_utils.cpp => mock_fast_app_module_json_utils.cpp} | 2 +- ...odule_json_utils.h => mock_fast_app_module_json_utils.h} | 6 +++--- .../multiapp_packager_test/multiapp_packager_test.cpp | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) rename packing_tool/frameworks/test/unittest/fast_app_packager_test/mock/{mock_fastapp_module_json_utils.cpp => mock_fast_app_module_json_utils.cpp} (99%) rename packing_tool/frameworks/test/unittest/fast_app_packager_test/mock/{mock_fastapp_module_json_utils.h => mock_fast_app_module_json_utils.h} (97%) diff --git a/packing_tool/frameworks/test/unittest/fast_app_packager_test/fast_app_packager_test.cpp b/packing_tool/frameworks/test/unittest/fast_app_packager_test/fast_app_packager_test.cpp index 9baa7759..200aa329 100644 --- a/packing_tool/frameworks/test/unittest/fast_app_packager_test/fast_app_packager_test.cpp +++ b/packing_tool/frameworks/test/unittest/fast_app_packager_test/fast_app_packager_test.cpp @@ -21,7 +21,7 @@ #define private public #define protected public #include "fast_app_packager.h" -#include "mock/mock_fastapp_module_json_utils.h" +#include "mock/mock_fast_app_module_json_utils.h" #undef private #undef protected diff --git a/packing_tool/frameworks/test/unittest/fast_app_packager_test/mock/mock_fastapp_module_json_utils.cpp b/packing_tool/frameworks/test/unittest/fast_app_packager_test/mock/mock_fast_app_module_json_utils.cpp similarity index 99% rename from packing_tool/frameworks/test/unittest/fast_app_packager_test/mock/mock_fastapp_module_json_utils.cpp rename to packing_tool/frameworks/test/unittest/fast_app_packager_test/mock/mock_fast_app_module_json_utils.cpp index 684287b9..3e83945a 100644 --- a/packing_tool/frameworks/test/unittest/fast_app_packager_test/mock/mock_fastapp_module_json_utils.cpp +++ b/packing_tool/frameworks/test/unittest/fast_app_packager_test/mock/mock_fast_app_module_json_utils.cpp @@ -21,7 +21,7 @@ #include "hap_verify_utils.h" #include "log.h" -#include "mock_fastapp_module_json_utils.h" +#include "mock_fast_app_module_json_utils.h" #include "module_json.h" #include "utils.h" #include "zip_utils.h" diff --git a/packing_tool/frameworks/test/unittest/fast_app_packager_test/mock/mock_fastapp_module_json_utils.h b/packing_tool/frameworks/test/unittest/fast_app_packager_test/mock/mock_fast_app_module_json_utils.h similarity index 97% rename from packing_tool/frameworks/test/unittest/fast_app_packager_test/mock/mock_fastapp_module_json_utils.h rename to packing_tool/frameworks/test/unittest/fast_app_packager_test/mock/mock_fast_app_module_json_utils.h index 4fef73b4..9ab013e5 100644 --- a/packing_tool/frameworks/test/unittest/fast_app_packager_test/mock/mock_fastapp_module_json_utils.h +++ b/packing_tool/frameworks/test/unittest/fast_app_packager_test/mock/mock_fast_app_module_json_utils.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef MOCK_FASTAPP_MODULE_JSON_UTILS_H -#define MOCK_FASTAPP_MODULE_JSON_UTILS_H +#ifndef MOCK_FAST_APP_MODULE_JSON_UTILS_H +#define MOCK_FAST_APP_MODULE_JSON_UTILS_H #include #include "hap_verify_info.h" @@ -113,4 +113,4 @@ public: } }; } // namespace OHOS -#endif // MOCK_FASTAPP_MODULE_JSON_UTILS_H \ No newline at end of file +#endif // MOCK_FAST_APP_MODULE_JSON_UTILS_H \ No newline at end of file diff --git a/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiapp_packager_test.cpp b/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiapp_packager_test.cpp index 4b8f115e..b58bfb7e 100644 --- a/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiapp_packager_test.cpp +++ b/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiapp_packager_test.cpp @@ -22,7 +22,7 @@ #define protected public #include "packager.h" #include "multiapp_packager.h" -#include "mock/mock_module_json_utils.h" +#include "mock/mock_multiapp_module_json_utils.h" #include "zip_wrapper.h" #include "zip_utils.h" #include "log.h" -- Gitee From 9d0486484d041e0f0d32335924743a05d9f10627 Mon Sep 17 00:00:00 2001 From: z30034863 Date: Fri, 6 Jun 2025 09:10:48 +0800 Subject: [PATCH 12/15] fix tdd 10 Signed-off-by: z30034863 --- .../frameworks/test/unittest/fast_app_packager_test/BUILD.gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packing_tool/frameworks/test/unittest/fast_app_packager_test/BUILD.gn b/packing_tool/frameworks/test/unittest/fast_app_packager_test/BUILD.gn index 85012e37..1c9067c9 100644 --- a/packing_tool/frameworks/test/unittest/fast_app_packager_test/BUILD.gn +++ b/packing_tool/frameworks/test/unittest/fast_app_packager_test/BUILD.gn @@ -47,7 +47,7 @@ ohos_unittest("fast_app_packager_test") { "../../../src/zip_utils.cpp", "../../../src/zip_wrapper.cpp", "fast_app_packager_test.cpp", - "mock/mock_fastapp_module_json_utils.cpp", + "mock/mock_fast_app_module_json_utils.cpp", ] external_deps = [ "bounds_checking_function:libsec_static", -- Gitee From 20c569448eee4dec1efb7d8495678ec0958082d1 Mon Sep 17 00:00:00 2001 From: z30034863 Date: Fri, 6 Jun 2025 10:08:59 +0800 Subject: [PATCH 13/15] fix tdd 11 Signed-off-by: z30034863 --- .../mock/mock_fast_app_module_json_utils.cpp | 68 +++++++++---------- .../mock/mock_fast_app_module_json_utils.h | 2 +- 2 files changed, 35 insertions(+), 35 deletions(-) diff --git a/packing_tool/frameworks/test/unittest/fast_app_packager_test/mock/mock_fast_app_module_json_utils.cpp b/packing_tool/frameworks/test/unittest/fast_app_packager_test/mock/mock_fast_app_module_json_utils.cpp index 3e83945a..be5920b1 100644 --- a/packing_tool/frameworks/test/unittest/fast_app_packager_test/mock/mock_fast_app_module_json_utils.cpp +++ b/packing_tool/frameworks/test/unittest/fast_app_packager_test/mock/mock_fast_app_module_json_utils.cpp @@ -31,22 +31,22 @@ namespace fs = std::filesystem; namespace OHOS { -bool MockModuleJsonUtils::mockGetStageHapVerifyInfo_ = false; -bool MockModuleJsonUtils::mockGetFaHapVerifyInfo_ = false; -bool MockModuleJsonUtils::mockCheckHapsIsValid_ = false; -bool MockModuleJsonUtils::mockIsModuleHap_ = false; -bool MockModuleJsonUtils::mockCheckHapsIsValidResult_ = false; -bool MockModuleJsonUtils::mockIsModuleHapResult_ = false; -bool MockModuleJsonUtils::mockCheckAppAtomicServiceCompressedSizeValid_ = false; -bool MockModuleJsonUtils::mockCheckAppAtomicServiceCompressedSizeValidResult_ = false; -bool MockModuleJsonUtils::mockGetHapVerifyInfosMapfromFileList_ = false; -bool MockModuleJsonUtils::mockGetHapVerifyInfosMapfromFileListResult_ = false; -ResultSeries MockModuleJsonUtils::mockGetStageHapVerifyInfoResultSeries_; +bool MockFastAppModuleJsonUtils::mockGetStageHapVerifyInfo_ = false; +bool MockFastAppModuleJsonUtils::mockGetFaHapVerifyInfo_ = false; +bool MockFastAppModuleJsonUtils::mockCheckHapsIsValid_ = false; +bool MockFastAppModuleJsonUtils::mockIsModuleHap_ = false; +bool MockFastAppModuleJsonUtils::mockCheckHapsIsValidResult_ = false; +bool MockFastAppModuleJsonUtils::mockIsModuleHapResult_ = false; +bool MockFastAppModuleJsonUtils::mockCheckAppAtomicServiceCompressedSizeValid_ = false; +bool MockFastAppModuleJsonUtils::mockCheckAppAtomicServiceCompressedSizeValidResult_ = false; +bool MockFastAppModuleJsonUtils::mockGetHapVerifyInfosMapfromFileList_ = false; +bool MockFastAppModuleJsonUtils::mockGetHapVerifyInfosMapfromFileListResult_ = false; +ResultSeries MockFastAppModuleJsonUtils::mockGetStageHapVerifyInfoResultSeries_; ResultSeries::const_iterator - MockModuleJsonUtils::mockGetStageHapVerifyInfoResultSeriesIter_ = mockGetStageHapVerifyInfoResultSeries_.cbegin(); -ResultSeries MockModuleJsonUtils::mockGetFaHapVerifyInfoResultSeries_; + MockFastAppModuleJsonUtils::mockGetStageHapVerifyInfoResultSeriesIter_ = mockGetStageHapVerifyInfoResultSeries_.cbegin(); +ResultSeries MockFastAppModuleJsonUtils::mockGetFaHapVerifyInfoResultSeries_; ResultSeries::const_iterator - MockModuleJsonUtils::mockGetFaHapVerifyInfoResultSeriesIter_ = mockGetFaHapVerifyInfoResultSeries_.cbegin(); + MockFastAppModuleJsonUtils::mockGetFaHapVerifyInfoResultSeriesIter_ = mockGetFaHapVerifyInfoResultSeries_.cbegin(); namespace AppPackingTool { namespace { @@ -67,13 +67,13 @@ static int32_t g_sumModuleSizeLimit = 10; // java : parseStageHapVerifyInfo bool ModuleJsonUtils::GetStageHapVerifyInfo(const std::string& hapFilePath, HapVerifyInfo& hapVerifyInfo) { - if (MockModuleJsonUtils::mockGetStageHapVerifyInfo_) { - const bool result = MockModuleJsonUtils::mockGetStageHapVerifyInfoResultSeriesIter_->first; - hapVerifyInfo = MockModuleJsonUtils::mockGetStageHapVerifyInfoResultSeriesIter_->second; + if (MockFastAppModuleJsonUtils::mockGetStageHapVerifyInfo_) { + const bool result = MockFastAppModuleJsonUtils::mockGetStageHapVerifyInfoResultSeriesIter_->first; + hapVerifyInfo = MockFastAppModuleJsonUtils::mockGetStageHapVerifyInfoResultSeriesIter_->second; - const auto next = MockModuleJsonUtils::mockGetStageHapVerifyInfoResultSeriesIter_ + 1; - if (next != MockModuleJsonUtils::mockGetStageHapVerifyInfoResultSeries_.cend()) { - MockModuleJsonUtils::mockGetStageHapVerifyInfoResultSeriesIter_ = next; + const auto next = MockFastAppModuleJsonUtils::mockGetStageHapVerifyInfoResultSeriesIter_ + 1; + if (next != MockFastAppModuleJsonUtils::mockGetStageHapVerifyInfoResultSeries_.cend()) { + MockFastAppModuleJsonUtils::mockGetStageHapVerifyInfoResultSeriesIter_ = next; } return result; @@ -112,13 +112,13 @@ bool ModuleJsonUtils::GetStageHapVerifyInfo(const std::string& hapFilePath, HapV bool ModuleJsonUtils::GetFaHapVerifyInfo(const std::string& hapFilePath, HapVerifyInfo& hapVerifyInfo) { - if (MockModuleJsonUtils::mockGetFaHapVerifyInfo_) { - const bool result = MockModuleJsonUtils::mockGetFaHapVerifyInfoResultSeriesIter_->first; - hapVerifyInfo = MockModuleJsonUtils::mockGetFaHapVerifyInfoResultSeriesIter_->second; + if (MockFastAppModuleJsonUtils::mockGetFaHapVerifyInfo_) { + const bool result = MockFastAppModuleJsonUtils::mockGetFaHapVerifyInfoResultSeriesIter_->first; + hapVerifyInfo = MockFastAppModuleJsonUtils::mockGetFaHapVerifyInfoResultSeriesIter_->second; - const auto next = MockModuleJsonUtils::mockGetFaHapVerifyInfoResultSeriesIter_ + 1; - if (next != MockModuleJsonUtils::mockGetFaHapVerifyInfoResultSeries_.cend()) { - MockModuleJsonUtils::mockGetFaHapVerifyInfoResultSeriesIter_ = next; + const auto next = MockFastAppModuleJsonUtils::mockGetFaHapVerifyInfoResultSeriesIter_ + 1; + if (next != MockFastAppModuleJsonUtils::mockGetFaHapVerifyInfoResultSeries_.cend()) { + MockFastAppModuleJsonUtils::mockGetFaHapVerifyInfoResultSeriesIter_ = next; } return result; @@ -208,8 +208,8 @@ bool ModuleJsonUtils::GetHapVerifyInfosfromFileList(const std::list bool ModuleJsonUtils::GetHapVerifyInfosMapfromFileList(const std::list& fileList, std::map>& hapVerifyInfoMap) { - if (MockModuleJsonUtils::mockGetHapVerifyInfosMapfromFileList_) { - return MockModuleJsonUtils::mockGetHapVerifyInfosMapfromFileListResult_; + if (MockFastAppModuleJsonUtils::mockGetHapVerifyInfosMapfromFileList_) { + return MockFastAppModuleJsonUtils::mockGetHapVerifyInfosMapfromFileListResult_; } for (auto& hapPath : fileList) { @@ -325,8 +325,8 @@ bool ModuleJsonUtils::CheckAppAtomicServiceCompressedSizeValid( std::map parameterMap, std::map>& hapVerifyInfoMap) { - if (MockModuleJsonUtils::mockCheckAppAtomicServiceCompressedSizeValid_) { - return MockModuleJsonUtils::mockCheckAppAtomicServiceCompressedSizeValidResult_; + if (MockFastAppModuleJsonUtils::mockCheckAppAtomicServiceCompressedSizeValid_) { + return MockFastAppModuleJsonUtils::mockCheckAppAtomicServiceCompressedSizeValidResult_; } if (!ValidateParameters(parameterMap)) { @@ -350,8 +350,8 @@ bool ModuleJsonUtils::CheckAppAtomicServiceCompressedSizeValid( // java : checkHapIsValid bool ModuleJsonUtils::CheckHapsIsValid(const std::list& fileList, const bool& isSharedApp) { - if (MockModuleJsonUtils::mockCheckHapsIsValid_) { - return MockModuleJsonUtils::mockCheckHapsIsValidResult_; + if (MockFastAppModuleJsonUtils::mockCheckHapsIsValid_) { + return MockFastAppModuleJsonUtils::mockCheckHapsIsValidResult_; } std::list hapVerifyInfos; @@ -386,8 +386,8 @@ bool ModuleJsonUtils::CheckHapsIsValid(const std::list& fileList, c bool ModuleJsonUtils::IsModuleHap(const std::string hapFilePath) { - if (MockModuleJsonUtils::mockIsModuleHap_) { - return MockModuleJsonUtils::mockIsModuleHapResult_; + if (MockFastAppModuleJsonUtils::mockIsModuleHap_) { + return MockFastAppModuleJsonUtils::mockIsModuleHapResult_; } return ZipUtils::IsFileExistsInZip(hapFilePath, MODULE_JSON); diff --git a/packing_tool/frameworks/test/unittest/fast_app_packager_test/mock/mock_fast_app_module_json_utils.h b/packing_tool/frameworks/test/unittest/fast_app_packager_test/mock/mock_fast_app_module_json_utils.h index 9ab013e5..5ad5b84b 100644 --- a/packing_tool/frameworks/test/unittest/fast_app_packager_test/mock/mock_fast_app_module_json_utils.h +++ b/packing_tool/frameworks/test/unittest/fast_app_packager_test/mock/mock_fast_app_module_json_utils.h @@ -24,7 +24,7 @@ namespace OHOS { using namespace OHOS::AppPackingTool; using ResultSeries = std::vector>; -class MockModuleJsonUtils { +class MockFastAppModuleJsonUtils { public: static bool mockGetStageHapVerifyInfo_; static bool mockGetFaHapVerifyInfo_; -- Gitee From c1859791b65f5dd408a3606730b93ca61f520363 Mon Sep 17 00:00:00 2001 From: z30034863 Date: Fri, 6 Jun 2025 11:01:24 +0800 Subject: [PATCH 14/15] fix tdd 12 Signed-off-by: z30034863 --- .../fast_app_packager_test/fast_app_packager_test.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packing_tool/frameworks/test/unittest/fast_app_packager_test/fast_app_packager_test.cpp b/packing_tool/frameworks/test/unittest/fast_app_packager_test/fast_app_packager_test.cpp index 200aa329..a4cccba7 100644 --- a/packing_tool/frameworks/test/unittest/fast_app_packager_test/fast_app_packager_test.cpp +++ b/packing_tool/frameworks/test/unittest/fast_app_packager_test/fast_app_packager_test.cpp @@ -174,8 +174,8 @@ HWTEST_F(FastAppPackagerTest, fastAppPackager_0100, Function | MediumTest | Leve "/data/test/resource/packingtool/test_file/pack.info"); system("cp -f /data/test/resource/packingtool/test_file/hap/entry/pack.json " "/data/test/resource/packingtool/test_file/hap/entry/pack.info"); - MockModuleJsonUtils::MockCheckAppAtomicServiceCompressedSizeValid(true); - MockModuleJsonUtils::MockGetHapVerifyInfosMapfromFileList(true); + MockFastAppModuleJsonUtils::MockCheckAppAtomicServiceCompressedSizeValid(true); + MockFastAppModuleJsonUtils::MockGetHapVerifyInfosMapfromFileList(true); EXPECT_EQ(fastAppackager.InitAllowedParam(), 0); EXPECT_EQ(fastAppackager.PreProcess(), 0); EXPECT_EQ(fastAppackager.Process(), 0); -- Gitee From 89abde2871a343249693f9602826984250b6a2ed Mon Sep 17 00:00:00 2001 From: z30034863 Date: Fri, 6 Jun 2025 11:47:06 +0800 Subject: [PATCH 15/15] fix tdd 13 Signed-off-by: z30034863 --- .../mock/mock_fast_app_module_json_utils.cpp | 3 +- .../mock/mock_multiapp_module_json_utils.cpp | 68 +++++++++---------- .../mock/mock_multiapp_module_json_utils.h | 2 +- .../multiapp_packager_test.cpp | 16 ++--- 4 files changed, 45 insertions(+), 44 deletions(-) diff --git a/packing_tool/frameworks/test/unittest/fast_app_packager_test/mock/mock_fast_app_module_json_utils.cpp b/packing_tool/frameworks/test/unittest/fast_app_packager_test/mock/mock_fast_app_module_json_utils.cpp index be5920b1..b76c197b 100644 --- a/packing_tool/frameworks/test/unittest/fast_app_packager_test/mock/mock_fast_app_module_json_utils.cpp +++ b/packing_tool/frameworks/test/unittest/fast_app_packager_test/mock/mock_fast_app_module_json_utils.cpp @@ -43,7 +43,8 @@ bool MockFastAppModuleJsonUtils::mockGetHapVerifyInfosMapfromFileList_ = false; bool MockFastAppModuleJsonUtils::mockGetHapVerifyInfosMapfromFileListResult_ = false; ResultSeries MockFastAppModuleJsonUtils::mockGetStageHapVerifyInfoResultSeries_; ResultSeries::const_iterator - MockFastAppModuleJsonUtils::mockGetStageHapVerifyInfoResultSeriesIter_ = mockGetStageHapVerifyInfoResultSeries_.cbegin(); + MockFastAppModuleJsonUtils::mockGetStageHapVerifyInfoResultSeriesIter_ = + mockGetStageHapVerifyInfoResultSeries_.cbegin(); ResultSeries MockFastAppModuleJsonUtils::mockGetFaHapVerifyInfoResultSeries_; ResultSeries::const_iterator MockFastAppModuleJsonUtils::mockGetFaHapVerifyInfoResultSeriesIter_ = mockGetFaHapVerifyInfoResultSeries_.cbegin(); diff --git a/packing_tool/frameworks/test/unittest/multiapp_packager_test/mock/mock_multiapp_module_json_utils.cpp b/packing_tool/frameworks/test/unittest/multiapp_packager_test/mock/mock_multiapp_module_json_utils.cpp index 8bcf1b9c..0d0395cb 100644 --- a/packing_tool/frameworks/test/unittest/multiapp_packager_test/mock/mock_multiapp_module_json_utils.cpp +++ b/packing_tool/frameworks/test/unittest/multiapp_packager_test/mock/mock_multiapp_module_json_utils.cpp @@ -31,22 +31,22 @@ namespace fs = std::filesystem; namespace OHOS { -bool MockModuleJsonUtils::mockGetStageHapVerifyInfo_ = false; -bool MockModuleJsonUtils::mockGetFaHapVerifyInfo_ = false; -bool MockModuleJsonUtils::mockCheckHapsIsValid_ = false; -bool MockModuleJsonUtils::mockIsModuleHap_ = false; -bool MockModuleJsonUtils::mockCheckHapsIsValidResult_ = false; -bool MockModuleJsonUtils::mockIsModuleHapResult_ = false; -bool MockModuleJsonUtils::mockCheckAppAtomicServiceCompressedSizeValid_ = false; -bool MockModuleJsonUtils::mockCheckAppAtomicServiceCompressedSizeValidResult_ = false; -bool MockModuleJsonUtils::mockGetHapVerifyInfosMapfromFileList_ = false; -bool MockModuleJsonUtils::mockGetHapVerifyInfosMapfromFileListResult_ = false; -ResultSeries MockModuleJsonUtils::mockGetStageHapVerifyInfoResultSeries_; +bool MockMultiAppModuleJsonUtils::mockGetStageHapVerifyInfo_ = false; +bool MockMultiAppModuleJsonUtils::mockGetFaHapVerifyInfo_ = false; +bool MockMultiAppModuleJsonUtils::mockCheckHapsIsValid_ = false; +bool MockMultiAppModuleJsonUtils::mockIsModuleHap_ = false; +bool MockMultiAppModuleJsonUtils::mockCheckHapsIsValidResult_ = false; +bool MockMultiAppModuleJsonUtils::mockIsModuleHapResult_ = false; +bool MockMultiAppModuleJsonUtils::mockCheckAppAtomicServiceCompressedSizeValid_ = false; +bool MockMultiAppModuleJsonUtils::mockCheckAppAtomicServiceCompressedSizeValidResult_ = false; +bool MockMultiAppModuleJsonUtils::mockGetHapVerifyInfosMapfromFileList_ = false; +bool MockMultiAppModuleJsonUtils::mockGetHapVerifyInfosMapfromFileListResult_ = false; +ResultSeries MockMultiAppModuleJsonUtils::mockGetStageHapVerifyInfoResultSeries_; ResultSeries::const_iterator - MockModuleJsonUtils::mockGetStageHapVerifyInfoResultSeriesIter_ = mockGetStageHapVerifyInfoResultSeries_.cbegin(); -ResultSeries MockModuleJsonUtils::mockGetFaHapVerifyInfoResultSeries_; + MockMultiAppModuleJsonUtils::mockGetStageHapVerifyInfoResultSeriesIter_ = mockGetStageHapVerifyInfoResultSeries_.cbegin(); +ResultSeries MockMultiAppModuleJsonUtils::mockGetFaHapVerifyInfoResultSeries_; ResultSeries::const_iterator - MockModuleJsonUtils::mockGetFaHapVerifyInfoResultSeriesIter_ = mockGetFaHapVerifyInfoResultSeries_.cbegin(); + MockMultiAppModuleJsonUtils::mockGetFaHapVerifyInfoResultSeriesIter_ = mockGetFaHapVerifyInfoResultSeries_.cbegin(); namespace AppPackingTool { namespace { @@ -67,13 +67,13 @@ static int32_t g_sumModuleSizeLimit = 10; // java : parseStageHapVerifyInfo bool ModuleJsonUtils::GetStageHapVerifyInfo(const std::string& hapFilePath, HapVerifyInfo& hapVerifyInfo) { - if (MockModuleJsonUtils::mockGetStageHapVerifyInfo_) { - const bool result = MockModuleJsonUtils::mockGetStageHapVerifyInfoResultSeriesIter_->first; - hapVerifyInfo = MockModuleJsonUtils::mockGetStageHapVerifyInfoResultSeriesIter_->second; + if (MockMultiAppModuleJsonUtils::mockGetStageHapVerifyInfo_) { + const bool result = MockMultiAppModuleJsonUtils::mockGetStageHapVerifyInfoResultSeriesIter_->first; + hapVerifyInfo = MockMultiAppModuleJsonUtils::mockGetStageHapVerifyInfoResultSeriesIter_->second; - const auto next = MockModuleJsonUtils::mockGetStageHapVerifyInfoResultSeriesIter_ + 1; - if (next != MockModuleJsonUtils::mockGetStageHapVerifyInfoResultSeries_.cend()) { - MockModuleJsonUtils::mockGetStageHapVerifyInfoResultSeriesIter_ = next; + const auto next = MockMultiAppModuleJsonUtils::mockGetStageHapVerifyInfoResultSeriesIter_ + 1; + if (next != MockMultiAppModuleJsonUtils::mockGetStageHapVerifyInfoResultSeries_.cend()) { + MockMultiAppModuleJsonUtils::mockGetStageHapVerifyInfoResultSeriesIter_ = next; } return result; @@ -112,13 +112,13 @@ bool ModuleJsonUtils::GetStageHapVerifyInfo(const std::string& hapFilePath, HapV bool ModuleJsonUtils::GetFaHapVerifyInfo(const std::string& hapFilePath, HapVerifyInfo& hapVerifyInfo) { - if (MockModuleJsonUtils::mockGetFaHapVerifyInfo_) { - const bool result = MockModuleJsonUtils::mockGetFaHapVerifyInfoResultSeriesIter_->first; - hapVerifyInfo = MockModuleJsonUtils::mockGetFaHapVerifyInfoResultSeriesIter_->second; + if (MockMultiAppModuleJsonUtils::mockGetFaHapVerifyInfo_) { + const bool result = MockMultiAppModuleJsonUtils::mockGetFaHapVerifyInfoResultSeriesIter_->first; + hapVerifyInfo = MockMultiAppModuleJsonUtils::mockGetFaHapVerifyInfoResultSeriesIter_->second; - const auto next = MockModuleJsonUtils::mockGetFaHapVerifyInfoResultSeriesIter_ + 1; - if (next != MockModuleJsonUtils::mockGetFaHapVerifyInfoResultSeries_.cend()) { - MockModuleJsonUtils::mockGetFaHapVerifyInfoResultSeriesIter_ = next; + const auto next = MockMultiAppModuleJsonUtils::mockGetFaHapVerifyInfoResultSeriesIter_ + 1; + if (next != MockMultiAppModuleJsonUtils::mockGetFaHapVerifyInfoResultSeries_.cend()) { + MockMultiAppModuleJsonUtils::mockGetFaHapVerifyInfoResultSeriesIter_ = next; } return result; @@ -208,8 +208,8 @@ bool ModuleJsonUtils::GetHapVerifyInfosfromFileList(const std::list bool ModuleJsonUtils::GetHapVerifyInfosMapfromFileList(const std::list& fileList, std::map>& hapVerifyInfoMap) { - if (MockModuleJsonUtils::mockGetHapVerifyInfosMapfromFileList_) { - return MockModuleJsonUtils::mockGetHapVerifyInfosMapfromFileListResult_; + if (MockMultiAppModuleJsonUtils::mockGetHapVerifyInfosMapfromFileList_) { + return MockMultiAppModuleJsonUtils::mockGetHapVerifyInfosMapfromFileListResult_; } for (auto& hapPath : fileList) { @@ -325,8 +325,8 @@ bool ModuleJsonUtils::CheckAppAtomicServiceCompressedSizeValid( std::map parameterMap, std::map>& hapVerifyInfoMap) { - if (MockModuleJsonUtils::mockCheckAppAtomicServiceCompressedSizeValid_) { - return MockModuleJsonUtils::mockCheckAppAtomicServiceCompressedSizeValidResult_; + if (MockMultiAppModuleJsonUtils::mockCheckAppAtomicServiceCompressedSizeValid_) { + return MockMultiAppModuleJsonUtils::mockCheckAppAtomicServiceCompressedSizeValidResult_; } if (!ValidateParameters(parameterMap)) { @@ -350,8 +350,8 @@ bool ModuleJsonUtils::CheckAppAtomicServiceCompressedSizeValid( // java : checkHapIsValid bool ModuleJsonUtils::CheckHapsIsValid(const std::list& fileList, const bool& isSharedApp) { - if (MockModuleJsonUtils::mockCheckHapsIsValid_) { - return MockModuleJsonUtils::mockCheckHapsIsValidResult_; + if (MockMultiAppModuleJsonUtils::mockCheckHapsIsValid_) { + return MockMultiAppModuleJsonUtils::mockCheckHapsIsValidResult_; } std::list hapVerifyInfos; @@ -386,8 +386,8 @@ bool ModuleJsonUtils::CheckHapsIsValid(const std::list& fileList, c bool ModuleJsonUtils::IsModuleHap(const std::string hapFilePath) { - if (MockModuleJsonUtils::mockIsModuleHap_) { - return MockModuleJsonUtils::mockIsModuleHapResult_; + if (MockMultiAppModuleJsonUtils::mockIsModuleHap_) { + return MockMultiAppModuleJsonUtils::mockIsModuleHapResult_; } return ZipUtils::IsFileExistsInZip(hapFilePath, MODULE_JSON); diff --git a/packing_tool/frameworks/test/unittest/multiapp_packager_test/mock/mock_multiapp_module_json_utils.h b/packing_tool/frameworks/test/unittest/multiapp_packager_test/mock/mock_multiapp_module_json_utils.h index 446feb11..1881f971 100644 --- a/packing_tool/frameworks/test/unittest/multiapp_packager_test/mock/mock_multiapp_module_json_utils.h +++ b/packing_tool/frameworks/test/unittest/multiapp_packager_test/mock/mock_multiapp_module_json_utils.h @@ -24,7 +24,7 @@ namespace OHOS { using namespace OHOS::AppPackingTool; using ResultSeries = std::vector>; -class MockModuleJsonUtils { +class MockMultiAppModuleJsonUtils { public: static bool mockGetStageHapVerifyInfo_; static bool mockGetFaHapVerifyInfo_; diff --git a/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiapp_packager_test.cpp b/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiapp_packager_test.cpp index b58bfb7e..fb982474 100644 --- a/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiapp_packager_test.cpp +++ b/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiapp_packager_test.cpp @@ -108,8 +108,8 @@ HWTEST_F(MultiAppPackagerTest, MultiAppPackager_0100, Function | MediumTest | Le }; OHOS::AppPackingTool::MultiAppPackager multiAppPackager(parameterMap, resultReceiver); - MockModuleJsonUtils::MockCheckAppAtomicServiceCompressedSizeValid(true); - MockModuleJsonUtils::MockGetHapVerifyInfosMapfromFileList(true); + MockMultiAppModuleJsonUtils::MockCheckAppAtomicServiceCompressedSizeValid(true); + MockMultiAppModuleJsonUtils::MockGetHapVerifyInfosMapfromFileList(true); EXPECT_EQ(multiAppPackager.InitAllowedParam(), 0); EXPECT_EQ(multiAppPackager.PreProcess(), 0); EXPECT_EQ(multiAppPackager.Process(), 0); @@ -303,8 +303,8 @@ HWTEST_F(MultiAppPackagerTest, PreProcess_1000, Function | MediumTest | Level1) }; OHOS::AppPackingTool::MultiAppPackager multiAppPackager(parameterMap, resultReceiver); - MockModuleJsonUtils::MockCheckAppAtomicServiceCompressedSizeValid(true); - MockModuleJsonUtils::MockGetHapVerifyInfosMapfromFileList(true); + MockMultiAppModuleJsonUtils::MockCheckAppAtomicServiceCompressedSizeValid(true); + MockMultiAppModuleJsonUtils::MockGetHapVerifyInfosMapfromFileList(true); EXPECT_EQ(multiAppPackager.PreProcess(), 1); } @@ -386,8 +386,8 @@ HWTEST_F(MultiAppPackagerTest, PreProcess_1400, Function | MediumTest | Level1) }; OHOS::AppPackingTool::MultiAppPackager multiAppPackager(parameterMap, resultReceiver); - MockModuleJsonUtils::MockCheckAppAtomicServiceCompressedSizeValid(true); - MockModuleJsonUtils::MockGetHapVerifyInfosMapfromFileList(true); + MockMultiAppModuleJsonUtils::MockCheckAppAtomicServiceCompressedSizeValid(true); + MockMultiAppModuleJsonUtils::MockGetHapVerifyInfosMapfromFileList(true); EXPECT_EQ(multiAppPackager.PreProcess(), 1); EXPECT_EQ(multiAppPackager.CompressAppModeForMultiProject(), true); } @@ -432,8 +432,8 @@ HWTEST_F(MultiAppPackagerTest, PreProcess_1600, Function | MediumTest | Level1) }; OHOS::AppPackingTool::MultiAppPackager multiAppPackager(parameterMap, resultReceiver); - MockModuleJsonUtils::MockCheckAppAtomicServiceCompressedSizeValid(true); - MockModuleJsonUtils::MockGetHapVerifyInfosMapfromFileList(true); + MockMultiAppModuleJsonUtils::MockCheckAppAtomicServiceCompressedSizeValid(true); + MockMultiAppModuleJsonUtils::MockGetHapVerifyInfosMapfromFileList(true); EXPECT_EQ(multiAppPackager.PreProcess(), 1); EXPECT_EQ(multiAppPackager.CompressAppModeForMultiProject(), true); } -- Gitee