From ab4fc9bbc955c7909c40db015da727ba318a3dbf Mon Sep 17 00:00:00 2001 From: ma_nan Date: Wed, 29 Sep 2021 19:41:12 +0800 Subject: [PATCH 1/5] fix ut codestyle Signed-off-by: ma_nan --- OAT.xml | 18 +++++++++++---- services/package/pkg_package/pkg_pkgfile.cpp | 2 -- .../applypatch_test/imagepatch_unittest.cpp | 9 ++++---- .../fs_manager/do_partition_unittest.cpp | 4 ++-- test/unittest/package/pkg_algo_unittest.cpp | 4 ++-- .../unittest/package/pkg_manager_unittest.cpp | 23 +++++++++++++------ test/unittest/package/pkg_test.h | 1 + test/unittest/script/script_unittest.cpp | 3 ++- .../updater_binary_unittest.cpp | 19 +++++++++++---- .../updater_main_unittest.cpp | 2 +- 10 files changed, 56 insertions(+), 29 deletions(-) diff --git a/OAT.xml b/OAT.xml index e52288de..e308ba55 100755 --- a/OAT.xml +++ b/OAT.xml @@ -65,14 +65,22 @@ Note:If the text contains special characters, please escape them according to th - + - - - - + + + + + + + + + + + + diff --git a/services/package/pkg_package/pkg_pkgfile.cpp b/services/package/pkg_package/pkg_pkgfile.cpp index afa0724d..5deac71e 100644 --- a/services/package/pkg_package/pkg_pkgfile.cpp +++ b/services/package/pkg_package/pkg_pkgfile.cpp @@ -34,8 +34,6 @@ PkgFile::~PkgFile() } pkgEntryMapId_.clear(); pkgEntryMapFileName_.clear(); - PkgManager::StreamPtr tmpStream = pkgStream_; - PkgManager::GetPackageInstance()->ClosePkgStream(tmpStream); } PkgEntryPtr PkgFile::AddPkgEntry(const std::string &fileName) diff --git a/test/unittest/applypatch_test/imagepatch_unittest.cpp b/test/unittest/applypatch_test/imagepatch_unittest.cpp index c9a1466c..15126bf3 100755 --- a/test/unittest/applypatch_test/imagepatch_unittest.cpp +++ b/test/unittest/applypatch_test/imagepatch_unittest.cpp @@ -53,7 +53,6 @@ bool ImagePatchTest::ReadContentFromFile(const std::string& file, std::string &c while ((n = read(fd, buffer, sizeof(buffer))) > 0) { content.append(buffer, n); } - close(fd); return ((n == 0) ? true : false); } @@ -73,7 +72,7 @@ int ImagePatchTest::TestZipModeImagePatch() const reinterpret_cast(sourceData.data()), sourceData.size(), reinterpret_cast(patchContent.data()), patchContent.size() }; - return RunImageApplyPatch(param, "out_put_zip.zip", expectedSHA256); + return RunImageApplyPatch(param, "/data/updater/applypatch/out_put_zip.zip", expectedSHA256); } int ImagePatchTest::TestNormalModeImagePatch() const @@ -90,7 +89,7 @@ int ImagePatchTest::TestNormalModeImagePatch() const reinterpret_cast(sourceData.data()), sourceData.size(), reinterpret_cast(patchContent.data()), patchContent.size() }; - return RunImageApplyPatch(param, "out_put_zip.zip", expectedSHA256); + return RunImageApplyPatch(param, "/data/updater/diffpatch/out_put_zip.zip", expectedSHA256); } int ImagePatchTest::TestGZipModeImagePatch() const @@ -106,7 +105,7 @@ int ImagePatchTest::TestGZipModeImagePatch() const reinterpret_cast(sourceData.data()), sourceData.size(), reinterpret_cast(patchContent.data()), patchContent.size() }; - int ret = RunImageApplyPatch(param, "out_put_gzip.gzip", expectedSHA256); + int ret = RunImageApplyPatch(param, "/data/updater/applypatch/out_put_gzip.gzip", expectedSHA256); return ret; } @@ -123,7 +122,7 @@ int ImagePatchTest::TestLZ4ModeImagePatch() const reinterpret_cast(sourceData.data()), sourceData.size(), reinterpret_cast(patchContent.data()), patchContent.size() }; - RunImageApplyPatch(param, "out_put_lz4.lz4", expectedSHA256); + RunImageApplyPatch(param, "/data/updater/diffpatch/out_put_lz4.lz4", expectedSHA256); return 0; } diff --git a/test/unittest/fs_manager/do_partition_unittest.cpp b/test/unittest/fs_manager/do_partition_unittest.cpp index cf0a03d7..672b20bd 100755 --- a/test/unittest/fs_manager/do_partition_unittest.cpp +++ b/test/unittest/fs_manager/do_partition_unittest.cpp @@ -122,8 +122,8 @@ HWTEST_F(DoPartitionUnitTest, do_partition_test_001, TestSize.Level1) int ret1 = RegisterUpdaterPartitionList(nList, olist); ASSERT_EQ(ret1, 1); - char aaa[BUFFER_SIZE]; - BlockDevice myDev; + char aaa[BUFFER_SIZE] = {0}; + BlockDevice myDev {}; myDev.devPath = "xxxxxx"; myDev.specific = (void *)aaa; SetBlockDeviceMode(myDev); diff --git a/test/unittest/package/pkg_algo_unittest.cpp b/test/unittest/package/pkg_algo_unittest.cpp index e78461bb..fbab4b1c 100755 --- a/test/unittest/package/pkg_algo_unittest.cpp +++ b/test/unittest/package/pkg_algo_unittest.cpp @@ -252,9 +252,9 @@ HWTEST_F(PkgAlgoUnitTest, TestInvalid, TestSize.Level1) HWTEST_F(PkgAlgoUnitTest, TestPkgAlgoDeflate, TestSize.Level1) { - ZipFileInfo info; + ZipFileInfo info {}; PkgAlgoDeflate a1(info); - Lz4FileInfo config; + Lz4FileInfo config {}; PkgAlgorithmLz4 a2(config); PkgAlgorithmBlockLz4 a3(config); VerifyAlgorithm a4("aa", 0); diff --git a/test/unittest/package/pkg_manager_unittest.cpp b/test/unittest/package/pkg_manager_unittest.cpp index d968d701..74034348 100755 --- a/test/unittest/package/pkg_manager_unittest.cpp +++ b/test/unittest/package/pkg_manager_unittest.cpp @@ -73,7 +73,7 @@ public: } const std::string GetFileName() const override { - return 0; + return ""; } size_t GetFileLength() override { @@ -188,7 +188,10 @@ public: // 测试文件提取 PkgManager::StreamPtr outStream = nullptr; const FileInfo *info = pkgManager_->GetFileInfo(components[0]); - EXPECT_NE(info, nullptr); + if (info == nullptr) { + return PKG_INVALID_FILE; + } + ret = pkgManager_->CreatePkgStream(outStream, components[0], info->unpackedSize, PkgStream::PkgStreamType_MemoryMap); EXPECT_NE(outStream, nullptr); @@ -266,7 +269,9 @@ public: // 测试文件提取 PkgManager::StreamPtr outStream = nullptr; const FileInfo *info = pkgManager_->GetFileInfo(components[0]); - EXPECT_NE(info, nullptr); + if (info == nullptr) { + return PKG_INVALID_FILE; + } ret = pkgManager_->CreatePkgStream(outStream, TEST_PATH_TO + components[0], info->unpackedSize, PkgStream::PkgStreamType_Write); @@ -303,7 +308,10 @@ public: // 测试文件提取 PkgManager::StreamPtr outStream = nullptr; const FileInfo *info = pkgManager_->GetFileInfo(components[0]); - EXPECT_NE(info, nullptr); + if (info == nullptr) { + return PKG_INVALID_FILE; + } + ret = pkgManager_->CreatePkgStream(outStream, components[0], TestStreamProcess, this); EXPECT_NE(outStream, nullptr); @@ -606,9 +614,10 @@ public: std::string testFileName = TEST_PATH_FROM + "../applypatch/TestDecompressGzip.new.gz"; size_t fileSize = GetFileSize(testFileName); size_t uncompressedDataSize = 1024; - int32_t fd = open(testFileName.c_str(), O_RDWR); - EXPECT_GE(fd, 0); - + int fd = open(testFileName.c_str(), O_RDWR); + if (fd < 0) { + return -1; + } uncompressedData.resize(uncompressedDataSize); PkgManager::StreamPtr stream = nullptr; pkgManager_->CreatePkgStream(stream, "Gzip", diff --git a/test/unittest/package/pkg_test.h b/test/unittest/package/pkg_test.h index badd45df..16a72a4d 100755 --- a/test/unittest/package/pkg_test.h +++ b/test/unittest/package/pkg_test.h @@ -118,6 +118,7 @@ protected: EXPECT_EQ(ret, 0); manager->ClosePkgStream(outStream); const FileInfo *info = manager->GetFileInfo(components[i]); + ASSERT_NE(info, nullptr); if (info->packMethod == PKG_COMPRESS_METHOD_NONE) { const ComponentInfo* compInfo = (const ComponentInfo*)manager->GetFileInfo(components[i]); if (compInfo != nullptr) { diff --git a/test/unittest/script/script_unittest.cpp b/test/unittest/script/script_unittest.cpp index e8bee2ae..f32fa7e6 100755 --- a/test/unittest/script/script_unittest.cpp +++ b/test/unittest/script/script_unittest.cpp @@ -72,6 +72,7 @@ public: virtual void DestoryInstructionInstance(UScriptInstructionPtr& instr) { delete instr; + instr = nullptr; } TestScriptInstructionFactory() {} virtual ~TestScriptInstructionFactory() {} @@ -108,8 +109,8 @@ public: { return isRetry; } -private: UScriptInstructionFactory *factory_ = nullptr; +private: bool isRetry = false; }; diff --git a/test/unittest/updater_binary/updater_binary_unittest.cpp b/test/unittest/updater_binary/updater_binary_unittest.cpp index 52fd11f5..76a0a63c 100755 --- a/test/unittest/updater_binary/updater_binary_unittest.cpp +++ b/test/unittest/updater_binary/updater_binary_unittest.cpp @@ -129,6 +129,9 @@ protected: ComponentInfoExt *comp = (ComponentInfoExt*)malloc( sizeof(ComponentInfoExt) * (testFileNames_.size() + fileNameIndex)); + if (comp == nullptr) { + return -1; + } for (size_t i = 0; i < testFileNames_.size(); i++) { BuildCompnentInfo(comp[i], testFileNames_[i], testFileNames_[i], componentType); } @@ -149,10 +152,18 @@ protected: free(comp[i].filePath); free(comp[i].version); } - free(pkgInfo.productUpdateId); - free(pkgInfo.softwareVersion); - free(pkgInfo.date); - free(pkgInfo.time); + if (pkgInfo.productUpdateId != nullptr) { + free(pkgInfo.productUpdateId); + } + if (pkgInfo.softwareVersion != nullptr) { + free(pkgInfo.softwareVersion); + } + if (pkgInfo.date != nullptr) { + free(pkgInfo.date); + } + if (pkgInfo.time != nullptr) { + free(pkgInfo.time); + } free(comp); return ret; } diff --git a/test/unittest/updater_main_test/updater_main_unittest.cpp b/test/unittest/updater_main_test/updater_main_unittest.cpp index a13bcbb5..5a696c0a 100755 --- a/test/unittest/updater_main_test/updater_main_unittest.cpp +++ b/test/unittest/updater_main_test/updater_main_unittest.cpp @@ -164,7 +164,7 @@ HWTEST_F(UpdaterMainUnitTest, updater_main_test_compress, TestSize.Level1) { const std::string testFile = "/data/sdcard/updater/test_compress.txt"; FILE *fp = fopen(testFile.c_str(), "w"); - EXPECT_NE(fp, nullptr); + ASSERT_NE(fp, nullptr); fclose(fp); CompressLogs(testFile); } -- Gitee From 891760aadd361400f1c089985aa3e7edb8099c90 Mon Sep 17 00:00:00 2001 From: ma_nan Date: Wed, 29 Sep 2021 19:45:15 +0800 Subject: [PATCH 2/5] fix ut codestyle Signed-off-by: ma_nan --- test/unittest/applypatch_test/imagepatch_unittest.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/test/unittest/applypatch_test/imagepatch_unittest.cpp b/test/unittest/applypatch_test/imagepatch_unittest.cpp index 15126bf3..f58c5fd5 100755 --- a/test/unittest/applypatch_test/imagepatch_unittest.cpp +++ b/test/unittest/applypatch_test/imagepatch_unittest.cpp @@ -53,6 +53,7 @@ bool ImagePatchTest::ReadContentFromFile(const std::string& file, std::string &c while ((n = read(fd, buffer, sizeof(buffer))) > 0) { content.append(buffer, n); } + close(fd); return ((n == 0) ? true : false); } -- Gitee From 7e574acbc1e4c6a2025a48b04ca45500e0868565 Mon Sep 17 00:00:00 2001 From: ma_nan Date: Wed, 29 Sep 2021 19:55:00 +0800 Subject: [PATCH 3/5] fix ut codestyle Signed-off-by: ma_nan --- test/unittest/applypatch_test/store_unittest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unittest/applypatch_test/store_unittest.cpp b/test/unittest/applypatch_test/store_unittest.cpp index 8f683f94..ca635702 100755 --- a/test/unittest/applypatch_test/store_unittest.cpp +++ b/test/unittest/applypatch_test/store_unittest.cpp @@ -62,6 +62,6 @@ HWTEST_F(StoreUnitTest, store_test_002, TestSize.Level1) Store::CreateNewSpace(storePath, true); std::vector buffer(4096, 0); std::string filename1 = "test_file1"; - EXPECT_EQ(Store::WriteDataToStore(storePath, filename1, buffer, -1), -1); + EXPECT_EQ(Store::WriteDataToStore(storePath, filename1, buffer, 0), -1); } } -- Gitee From 23311502e803c10fa3d4b8a270db06fb1247527e Mon Sep 17 00:00:00 2001 From: ma_nan Date: Wed, 29 Sep 2021 20:23:31 +0800 Subject: [PATCH 4/5] fix ut codestyle Signed-off-by: ma_nan --- test/unittest/applypatch_test/store_unittest.cpp | 4 ++-- test/unittest/package/pkg_manager_unittest.cpp | 2 +- test/unittest/updater_binary/updater_binary_unittest.cpp | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/test/unittest/applypatch_test/store_unittest.cpp b/test/unittest/applypatch_test/store_unittest.cpp index ca635702..aa407f3a 100755 --- a/test/unittest/applypatch_test/store_unittest.cpp +++ b/test/unittest/applypatch_test/store_unittest.cpp @@ -58,10 +58,10 @@ HWTEST_F(StoreUnitTest, store_test_001, TestSize.Level1) HWTEST_F(StoreUnitTest, store_test_002, TestSize.Level1) { - std::string storePath = "/data/updater/ut_test"; + std::string storePath = ""; Store::CreateNewSpace(storePath, true); std::vector buffer(4096, 0); std::string filename1 = "test_file1"; - EXPECT_EQ(Store::WriteDataToStore(storePath, filename1, buffer, 0), -1); + EXPECT_EQ(Store::WriteDataToStore(storePath, filename1, buffer, buffer.size()), -1); } } diff --git a/test/unittest/package/pkg_manager_unittest.cpp b/test/unittest/package/pkg_manager_unittest.cpp index 74034348..ec795918 100755 --- a/test/unittest/package/pkg_manager_unittest.cpp +++ b/test/unittest/package/pkg_manager_unittest.cpp @@ -190,7 +190,7 @@ public: const FileInfo *info = pkgManager_->GetFileInfo(components[0]); if (info == nullptr) { return PKG_INVALID_FILE; - } + } ret = pkgManager_->CreatePkgStream(outStream, components[0], info->unpackedSize, PkgStream::PkgStreamType_MemoryMap); diff --git a/test/unittest/updater_binary/updater_binary_unittest.cpp b/test/unittest/updater_binary/updater_binary_unittest.cpp index 76a0a63c..770adb21 100755 --- a/test/unittest/updater_binary/updater_binary_unittest.cpp +++ b/test/unittest/updater_binary/updater_binary_unittest.cpp @@ -131,7 +131,7 @@ protected: sizeof(ComponentInfoExt) * (testFileNames_.size() + fileNameIndex)); if (comp == nullptr) { return -1; - } + } for (size_t i = 0; i < testFileNames_.size(); i++) { BuildCompnentInfo(comp[i], testFileNames_[i], testFileNames_[i], componentType); } @@ -152,7 +152,7 @@ protected: free(comp[i].filePath); free(comp[i].version); } - if (pkgInfo.productUpdateId != nullptr) { + if (pkgInfo.productUpdateId != nullptr) { free(pkgInfo.productUpdateId); } if (pkgInfo.softwareVersion != nullptr) { @@ -161,7 +161,7 @@ protected: if (pkgInfo.date != nullptr) { free(pkgInfo.date); } - if (pkgInfo.time != nullptr) { + if (pkgInfo.time != nullptr) { free(pkgInfo.time); } free(comp); -- Gitee From f0f14459d2490a07c0e2c108633c0db09dbfc234 Mon Sep 17 00:00:00 2001 From: ma_nan Date: Thu, 30 Sep 2021 17:14:39 +0800 Subject: [PATCH 5/5] fix ut codestyle Signed-off-by: ma_nan --- test/unittest/applypatch_test/store_unittest.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/test/unittest/applypatch_test/store_unittest.cpp b/test/unittest/applypatch_test/store_unittest.cpp index aa407f3a..237ed9e8 100755 --- a/test/unittest/applypatch_test/store_unittest.cpp +++ b/test/unittest/applypatch_test/store_unittest.cpp @@ -58,10 +58,7 @@ HWTEST_F(StoreUnitTest, store_test_001, TestSize.Level1) HWTEST_F(StoreUnitTest, store_test_002, TestSize.Level1) { - std::string storePath = ""; - Store::CreateNewSpace(storePath, true); std::vector buffer(4096, 0); - std::string filename1 = "test_file1"; - EXPECT_EQ(Store::WriteDataToStore(storePath, filename1, buffer, buffer.size()), -1); + EXPECT_EQ(Store::WriteDataToStore("", "test_file1", buffer, buffer.size()), -1); } } -- Gitee