From bdbdefd8fcf4ea6d3347e8770a4cb487ad7d1987 Mon Sep 17 00:00:00 2001 From: ma_nan Date: Tue, 28 Sep 2021 17:14:19 +0800 Subject: [PATCH 1/3] fix ut codestyle Signed-off-by: ma_nan --- .../applypatch_test/all_cmd_unittest.cpp | 8 ++--- .../applypatch_test/applypatch_unittest.cpp | 10 ++++-- .../applypatch_test/blockset_unittest.cpp | 20 ++++++++--- .../applypatch_test/commands_unittest.cpp | 6 ++-- .../applypatch_test/imagepatch_unittest.cpp | 2 ++ .../applypatch_test/imagepatch_unittest.h | 2 +- .../fs_manager/do_partition_unittest.cpp | 3 +- .../misc_info_test/misc_info_unittest.cpp | 9 ++--- test/unittest/mount_test/mount_unittest.cpp | 3 +- .../unittest/package/pkg_manager_unittest.cpp | 8 ++--- .../script/script_interpreter_unittest.cpp | 22 ++++++------- .../update_processor_unittest.cpp | 5 +++ .../updater_main_unittest.cpp | 33 +++++++++++-------- 13 files changed, 81 insertions(+), 50 deletions(-) diff --git a/test/unittest/applypatch_test/all_cmd_unittest.cpp b/test/unittest/applypatch_test/all_cmd_unittest.cpp index 5e712fa2..b4e19a4d 100755 --- a/test/unittest/applypatch_test/all_cmd_unittest.cpp +++ b/test/unittest/applypatch_test/all_cmd_unittest.cpp @@ -98,7 +98,7 @@ bool AllCmdUnitTest::WriteTestBin(int fd, const uint8_t &data, size_t size) cons // new command is not easy to simulate, it depends on // compression and other condition. // Leave new command to be covered by update_image_block test. -HWTEST_F(AllCmdUnitTest, allCmd_test_001, TestSize.Level1) +HWTEST_F(AllCmdUnitTest, allCmd_test_001,TestSize.Level1) { TransferManager *tm = TransferManager::GetTransferManagerInstance(); // Read source @@ -164,7 +164,7 @@ int AllCmdUnitTest::AllCmdUnitTestMove(int &fd, std::vector &allCmd return 0; } -HWTEST_F(AllCmdUnitTest, allCmd_test_002, TestSize.Level1) +HWTEST_F(AllCmdUnitTest, allCmd_test_002,TestSize.Level1) { TransferManagerPtr tm = TransferManager::GetTransferManagerInstance(); std::string filePath = "/tmp/test.bin"; @@ -176,11 +176,11 @@ HWTEST_F(AllCmdUnitTest, allCmd_test_002, TestSize.Level1) utils::MkdirRecursive(TransferManager::GetTransferManagerInstance()->GetGlobalParams()->storeBase, dirMode); std::vector buffer(bufferSize, 0); int fd = open(filePath.c_str(), O_RDWR | O_CREAT, dirMode); - lseek64(fd, 0, SEEK_SET); - if (fd == -1) { + if (fd < 0) { printf("Failed to open block %s, errno: %d\n", filePath.c_str(), errno); return; } + lseek64(fd, 0, SEEK_SET); auto res = WriteTestBin(fd, *buffer.data(), bufferSize * count); if (!res) { printf("Write to bin error\n"); diff --git a/test/unittest/applypatch_test/applypatch_unittest.cpp b/test/unittest/applypatch_test/applypatch_unittest.cpp index 6cc31833..4f70a0ef 100755 --- a/test/unittest/applypatch_test/applypatch_unittest.cpp +++ b/test/unittest/applypatch_test/applypatch_unittest.cpp @@ -92,7 +92,7 @@ HWTEST_F(ApplyPatchUnitTest, updater_RawWriter, TestSize.Level1) EXPECT_TRUE(ret); int fd = open(devPath.c_str(), O_RDONLY); - EXPECT_GT(fd, 0); + EXPECT_GE(fd, 0); uint8_t buffer[BUFFER_LEN + 1] = {0}; size_t n = read(fd, buffer, BUFFER_LEN); @@ -116,7 +116,13 @@ HWTEST_F(ApplyPatchUnitTest, updater_DataWriterOpenPartition, TestSize.Level1) partitionName = "/rawwriter"; auto devPath = GetBlockDeviceByMountPoint(partitionName); - close(open(devPath.c_str(), O_CREAT | O_WRONLY | O_EXCL, 0664)); + int fd = open(devPath.c_str(), O_CREAT | O_WRONLY | O_EXCL, 0664); + if (fd < 0) { + printf("Open %s failed", devPath.c_str()); + FAIL(); + return; + } + close(fd); writer = DataWriter::CreateDataWriter(mode, partitionName); EXPECT_NE(writer, nullptr); ret = writer->OpenPartition(partitionName); diff --git a/test/unittest/applypatch_test/blockset_unittest.cpp b/test/unittest/applypatch_test/blockset_unittest.cpp index 6d948e84..33144ec0 100755 --- a/test/unittest/applypatch_test/blockset_unittest.cpp +++ b/test/unittest/applypatch_test/blockset_unittest.cpp @@ -39,7 +39,7 @@ void BlockSetUnitTest::TearDown(void) cout << "TearDownTestCase" << endl; } -HWTEST_F(BlockSetUnitTest, blockset_test_001, TestSize.Level1) +HWTEST_F(BlockSetUnitTest, blockset_test_001,TestSize.Level1) { cout << "Blockset ut start"; BlockSet block(std::vector {BlockPair{0, 1}}); @@ -66,7 +66,7 @@ HWTEST_F(BlockSetUnitTest, blockset_test_001, TestSize.Level1) EXPECT_EQ(ret, -1); } -HWTEST_F(BlockSetUnitTest, blockset_test_002, TestSize.Level1) +HWTEST_F(BlockSetUnitTest, blockset_test_002,TestSize.Level1) { cout << "Blockset ut two blocks overlap"; BlockSet block(std::vector {BlockPair{0, 1}}); @@ -78,7 +78,7 @@ HWTEST_F(BlockSetUnitTest, blockset_test_002, TestSize.Level1) EXPECT_EQ(ret, false); } -HWTEST_F(BlockSetUnitTest, blockset_test_003, TestSize.Level1) +HWTEST_F(BlockSetUnitTest, blockset_test_003,TestSize.Level1) { cout << "Blockset ut two blocks overlap"; std::vector buffer; @@ -87,10 +87,15 @@ HWTEST_F(BlockSetUnitTest, blockset_test_003, TestSize.Level1) std::fill(buffer.begin(), buffer.end(), 0); std::string filename = "/tmp/ut_blockset"; int fd = open(filename.c_str(), O_RDWR); + if (fd < 0) { + printf("Open file failed"); + return; + } blk.WriteDataToBlock(fd, buffer); + close(fd); } -HWTEST_F(BlockSetUnitTest, blockset_test_004, TestSize.Level1) +HWTEST_F(BlockSetUnitTest, blockset_test_004,TestSize.Level1) { cout << "Blockset ut two blocks overlap"; std::vector srcBuffer; @@ -103,12 +108,16 @@ HWTEST_F(BlockSetUnitTest, blockset_test_004, TestSize.Level1) BlockSet::MoveBlock(srcBuffer, blk, tgtBuffer); } -HWTEST_F(BlockSetUnitTest, blockset_test_005, TestSize.Level1) +HWTEST_F(BlockSetUnitTest, blockset_test_005,TestSize.Level1) { std::string hashValue = "5aa246ebe8e817740f12cc0f6e536c5ea22e5db177563a1caea5a86614275546"; std::string blockInfo = "2,20755,21031 276 2,20306,20582"; std::string cmdLine = std::string("move ") + hashValue + " " + blockInfo; int fd = open("/data/updater/updater/blocksetTest.txt", O_CREAT | O_WRONLY, S_IRWXU | S_IRWXG | S_IRWXO); + if (fd < 0) { + printf("Open file failed"); + return; + } Command *cmd = new Command(); cmd->Init(cmdLine); cmd->SetFileDescriptor(fd); @@ -122,5 +131,6 @@ HWTEST_F(BlockSetUnitTest, blockset_test_005, TestSize.Level1) ret = targetBlock.WriteDiffToBlock(const_cast(*cmd), buffer, tgtBlockSize, isImgDiff); EXPECT_EQ(ret, -1); close(fd); + delete cmd; } } diff --git a/test/unittest/applypatch_test/commands_unittest.cpp b/test/unittest/applypatch_test/commands_unittest.cpp index 59249952..0b1cf868 100755 --- a/test/unittest/applypatch_test/commands_unittest.cpp +++ b/test/unittest/applypatch_test/commands_unittest.cpp @@ -49,7 +49,7 @@ void CommandsUnitTest::TearDown() cout << "Updater Unit CommandsUnitTest End!" << endl; } -HWTEST_F(CommandsUnitTest, command_test_001, TestSize.Level0) +HWTEST_F(CommandsUnitTest, command_test_001, TestSize.Level1) { std::string hashValue = "5aa246ebe8e817740f12cc0f6e536c5ea22e5db177563a1caea5a86614275546"; std::string blockInfo = "2,20755,21031 276 2,20306,20582"; @@ -62,9 +62,10 @@ HWTEST_F(CommandsUnitTest, command_test_001, TestSize.Level0) sha256 = cmd->GetArgumentByPos(1); EXPECT_EQ(sha256, "5aa246ebe8e817740f12cc0f6e536c5ea22e5db177563a1caea5a86614275546"); EXPECT_EQ(cmd->GetCommandLine(), cmdLine); + delete cmd; } -HWTEST_F(CommandsUnitTest, command_test_002, TestSize.Level0) +HWTEST_F(CommandsUnitTest, command_test_002,TestSize.Level1) { std::string hashValue = "5aa246ebe8e817740f12cc0f6e536c5ea22e5db177563a1caea5a86614275546"; std::string blockInfo = "2,20755,21031 276 2,20306,20582"; @@ -91,5 +92,6 @@ HWTEST_F(CommandsUnitTest, command_test_002, TestSize.Level0) EXPECT_EQ(cmd->Init(cmdLine), true); cmdLine = "last 1,1"; EXPECT_EQ(cmd->Init(cmdLine), true); + delete cmd; } } // updater_ut diff --git a/test/unittest/applypatch_test/imagepatch_unittest.cpp b/test/unittest/applypatch_test/imagepatch_unittest.cpp index 71388147..0266493a 100755 --- a/test/unittest/applypatch_test/imagepatch_unittest.cpp +++ b/test/unittest/applypatch_test/imagepatch_unittest.cpp @@ -53,6 +53,8 @@ bool ImagePatchTest::ReadContentFromFile(const std::string& file, std::string &c while ((n = read(fd, buffer, sizeof(buffer))) > 0) { content.append(buffer, n); } + printf("ReadContentFromFile %s %d \n", file.c_str(), n); + close(fd); return ((n == 0) ? true : false); } diff --git a/test/unittest/applypatch_test/imagepatch_unittest.h b/test/unittest/applypatch_test/imagepatch_unittest.h index efff589c..6da5f553 100755 --- a/test/unittest/applypatch_test/imagepatch_unittest.h +++ b/test/unittest/applypatch_test/imagepatch_unittest.h @@ -75,7 +75,7 @@ public: { mode_t mode = (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); int fd = open(target.c_str(), O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC | O_BINARY, mode); - EXPECT_GT(fd, 0); + EXPECT_GE(fd, 0); BlockSet targetBlk; targetBlk.ParserAndInsert({ "2", "0", "1" diff --git a/test/unittest/fs_manager/do_partition_unittest.cpp b/test/unittest/fs_manager/do_partition_unittest.cpp index cf0a03d7..d7cd7998 100755 --- a/test/unittest/fs_manager/do_partition_unittest.cpp +++ b/test/unittest/fs_manager/do_partition_unittest.cpp @@ -116,7 +116,8 @@ HWTEST_F(DoPartitionUnitTest, do_partition_test_001, TestSize.Level1) ASSERT_GT(ret, 0); PartitonList olist; - size_t xxxPartitionStart = dataPartitionStart + XXX_PARTITION_LEN; + size_t xxxPartitionStart = dataPartitionStart + XXX_PARTITION_LEN; + InitEmmcPartition(myPaty[partitionIndex], "xxxxxx", xxxPartitionStart, XXX_PARTITION_LEN); olist.push_back(&myPaty[partitionIndex]); int ret1 = RegisterUpdaterPartitionList(nList, olist); diff --git a/test/unittest/misc_info_test/misc_info_unittest.cpp b/test/unittest/misc_info_test/misc_info_unittest.cpp index dd3b1545..0895b703 100755 --- a/test/unittest/misc_info_test/misc_info_unittest.cpp +++ b/test/unittest/misc_info_test/misc_info_unittest.cpp @@ -42,10 +42,11 @@ HWTEST_F(MiscInfoUnitTest, misc_info_test_001, TestSize.Level1) auto fp = std::unique_ptr(fopen(MISC_FILE.c_str(), "wb"), fclose); EXPECT_NE(fp, nullptr); - UpdateMessage boot {}; - EXPECT_EQ(strncpy_s(boot.command, sizeof(boot.command), "boot_updater", sizeof(boot.command)), 0); - EXPECT_EQ(strncpy_s(boot.update, sizeof(boot.update), - "--update_package=./updater/xxx.zip\n--retry_count=1", sizeof(boot.update)), 0); + UpdateMessage boot {}; + const std::string command1 = "boot_updater"; + EXPECT_EQ(strncpy_s(boot.command, sizeof(boot.command) - 1, command1.c_str(), command1.size()), 0); + const std::string command2 = "--update_package=./updater/xxx.zip\n--retry_count=1"; + EXPECT_EQ(strncpy_s(boot.update, sizeof(boot.update) - 1, command2.c_str(), command2.size()), 0); bool ret = WriteUpdaterMessage(MISC_FILE, boot); EXPECT_EQ(ret, true); diff --git a/test/unittest/mount_test/mount_unittest.cpp b/test/unittest/mount_test/mount_unittest.cpp index 832a936d..80f80b8d 100755 --- a/test/unittest/mount_test/mount_unittest.cpp +++ b/test/unittest/mount_test/mount_unittest.cpp @@ -177,8 +177,9 @@ HWTEST_F(MountUnitTest, GetBlockDeviceByMountPoint_unitest, TestSize.Level1) std::cout << "Cannot re-mount vendor\n"; } auto ret = open(tmpPath.c_str(), O_RDONLY|O_CREAT|O_TRUNC, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); - if (ret != 0 && errno != EEXIST) { + if (ret < 0) { std::cout << "Cannot open \"/vendor/etc/fstab.updater\" file: " << errno << "\n"; + return; } close(ret); LoadFstab(); diff --git a/test/unittest/package/pkg_manager_unittest.cpp b/test/unittest/package/pkg_manager_unittest.cpp index 54bb964a..d968d701 100755 --- a/test/unittest/package/pkg_manager_unittest.cpp +++ b/test/unittest/package/pkg_manager_unittest.cpp @@ -528,7 +528,6 @@ public: (void)start; (void)buffer; size_t oldSize = uncompressedData.size(); - PKG_CHECK(oldSize != 0, return -1, "oldSize is 0"); if ((start + size) > uncompressedData.size()) { uncompressedData.resize(oldSize * ((start + size) / oldSize + 1)); } @@ -540,7 +539,7 @@ public: [&](hpackage::PkgManager::StreamPtr stream) { pkgManager_->ClosePkgStream(stream); }); - PKG_CHECK(outStream != nullptr, return -1, "Can not create stream "); + PKG_CHECK(outStream != nullptr, close(fd); return -1, "Can not create stream "); void* mappedData = mmap(nullptr, (size_t)fileSize, PROT_READ, MAP_SHARED, fd, 0); PKG_CHECK(mappedData != MAP_FAILED, close(fd); return -2, "Can not mmap "); @@ -608,7 +607,7 @@ public: size_t fileSize = GetFileSize(testFileName); size_t uncompressedDataSize = 1024; int32_t fd = open(testFileName.c_str(), O_RDWR); - EXPECT_GT(fd, 0); + EXPECT_GE(fd, 0); uncompressedData.resize(uncompressedDataSize); PkgManager::StreamPtr stream = nullptr; @@ -620,7 +619,6 @@ public: (void)start; (void)buffer; size_t oldSize = uncompressedData.size(); - PKG_CHECK(oldSize != 0, return -1, "oldSize is 0"); if ((start + size) > uncompressedData.size()) { uncompressedData.resize(oldSize * ((start + size) / oldSize + 1)); } @@ -632,7 +630,7 @@ public: [&](hpackage::PkgManager::StreamPtr stream) { pkgManager_->ClosePkgStream(stream); }); - PKG_CHECK(outStream != nullptr, return -1, "Can not create stream "); + PKG_CHECK(outStream != nullptr, close(fd); return -1, "Can not create stream "); void* mappedData = mmap(nullptr, (size_t)fileSize, PROT_READ, MAP_SHARED, fd, 0); PKG_CHECK(mappedData != MAP_FAILED, close(fd); return -2, "Can not mmap "); diff --git a/test/unittest/script/script_interpreter_unittest.cpp b/test/unittest/script/script_interpreter_unittest.cpp index db031a77..68e79b53 100755 --- a/test/unittest/script/script_interpreter_unittest.cpp +++ b/test/unittest/script/script_interpreter_unittest.cpp @@ -101,15 +101,15 @@ public: { std::unique_ptr funcContext = std::make_unique(); int intValue = 100; - int ret = funcContext->PushParam(intValue); + int ret1 = funcContext->PushParam(intValue); float floatValue = 100.0; - ret |= funcContext->PushParam(floatValue); + int ret2 = funcContext->PushParam(floatValue); std::string str = std::string("333333333"); - ret |= funcContext->PushParam(str); - EXPECT_EQ(0, ret); + int ret3 = funcContext->PushParam(str); + EXPECT_EQ(0, ret1 && ret2 && ret3); int32_t outOfIndex = 3; - ret = funcContext->GetParamType(outOfIndex); + int ret = funcContext->GetParamType(outOfIndex); EXPECT_EQ(UScriptContext::PARAM_TYPE_INVALID, ret); return 0; } @@ -192,37 +192,37 @@ protected: void TestBody() {} }; -HWTEST_F(ScriptInterpreterUnitTest, TestScriptInterpreterScriptValue, TestSize.Level0) +HWTEST_F(ScriptInterpreterUnitTest, TestScriptInterpreterScriptValue, TestSize.Level1) { ScriptInterpreterUnitTest test; EXPECT_EQ(0, test.TestScriptInterpreterScriptValue()); } -HWTEST_F(ScriptInterpreterUnitTest, TestScriptInstructionContext, TestSize.Level0) +HWTEST_F(ScriptInterpreterUnitTest, TestScriptInstructionContext, TestSize.Level1) { ScriptInterpreterUnitTest test; EXPECT_EQ(0, test.TestScriptInstructionContext()); } -HWTEST_F(ScriptInterpreterUnitTest, TestIntegerValueComputer, TestSize.Level0) +HWTEST_F(ScriptInterpreterUnitTest, TestIntegerValueComputer, TestSize.Level1) { ScriptInterpreterUnitTest test; EXPECT_EQ(0, test.TestIntegerValueComputer()); } -HWTEST_F(ScriptInterpreterUnitTest, TestFloatValueComputer, TestSize.Level0) +HWTEST_F(ScriptInterpreterUnitTest, TestFloatValueComputer, TestSize.Level1) { ScriptInterpreterUnitTest test; EXPECT_EQ(0, test.TestFloatValueComputer()); } -HWTEST_F(ScriptInterpreterUnitTest, TestStringValueComputer, TestSize.Level0) +HWTEST_F(ScriptInterpreterUnitTest, TestStringValueComputer, TestSize.Level1) { ScriptInterpreterUnitTest test; EXPECT_EQ(0, test.TestStringValueComputer()); } -HWTEST_F(ScriptInterpreterUnitTest, SomeDestructor, TestSize.Level0) +HWTEST_F(ScriptInterpreterUnitTest, SomeDestructor, TestSize.Level1) { IntegerValue a1(0); FloatValue a2(0.0); diff --git a/test/unittest/updater_binary/update_processor_unittest.cpp b/test/unittest/updater_binary/update_processor_unittest.cpp index d8ff4857..e86e72ee 100755 --- a/test/unittest/updater_binary/update_processor_unittest.cpp +++ b/test/unittest/updater_binary/update_processor_unittest.cpp @@ -72,6 +72,11 @@ HWTEST_F(UpdateProcessorUnitTest, UpdateProcessor_001, TestSize.Level1) updater::utils::MkdirRecursive(devDir, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); int fd = open(devPath.c_str(), O_CREAT | O_WRONLY | O_EXCL, 0664); printf("@@@ devPath = %s, fd=%d\n", devPath.c_str(), fd); + if (fd < 0) { + printf("Open failed, fd = %d", fd); + FAIL(); + return; + } close(fd); for (int32_t i = 0; i < ScriptManager::MAX_PRIORITY; i++) { diff --git a/test/unittest/updater_main_test/updater_main_unittest.cpp b/test/unittest/updater_main_test/updater_main_unittest.cpp index 9f2dad4b..a13bcbb5 100755 --- a/test/unittest/updater_main_test/updater_main_unittest.cpp +++ b/test/unittest/updater_main_test/updater_main_unittest.cpp @@ -26,7 +26,7 @@ #include "updater_ui.h" #include "utils.h" -using namespace updater; +using namespace updater; using namespace testing::ext; using namespace std; using namespace updater::utils; @@ -76,7 +76,8 @@ HWTEST_F(UpdaterMainUnitTest, updater_main_test_001, TestSize.Level1) const std::string commandFile = "/data/updater/command"; auto fp = std::unique_ptr(fopen(commandFile.c_str(), "wb"), fclose); EXPECT_NE(fp, nullptr); - EXPECT_EQ(strncpy_s(boot.command, sizeof(boot.command), "boot_updater", sizeof(boot.command)), 0); + const std::string commandMsg = "boot_updater"; + EXPECT_EQ(strncpy_s(boot.command, sizeof(boot.command) - 1, commandMsg.c_str(), commandMsg.size()), 0); EXPECT_EQ(strncpy_s(boot.update, sizeof(boot.update), "", sizeof(boot.update)), 0); bool bRet = WriteUpdaterMessage(commandFile, boot); EXPECT_EQ(bRet, true); @@ -95,8 +96,10 @@ HWTEST_F(UpdaterMainUnitTest, updater_main_test_001, TestSize.Level1) HWTEST_F(UpdaterMainUnitTest, updater_main_test_002, TestSize.Level1) { UpdateMessage boot {}; - EXPECT_EQ(strncpy_s(boot.command, sizeof(boot.command), "boot_updater", sizeof(boot.command)), 0); - EXPECT_EQ(strncpy_s(boot.update, sizeof(boot.update), "--user_wipe_data", sizeof(boot.update)), 0); + const std::string command1 = "boot_updater"; + EXPECT_EQ(strncpy_s(boot.command, sizeof(boot.command) - 1, command1.c_str(), command1.size()), 0); + const std::string command2 = "--user_wipe_data"; + EXPECT_EQ(strncpy_s(boot.update, sizeof(boot.update) - 1, command2.c_str(), command2.size()), 0); bool ret = WriteUpdaterMessage(MISC_FILE, boot); EXPECT_EQ(ret, true); @@ -114,7 +117,6 @@ HWTEST_F(UpdaterMainUnitTest, updater_main_test_003, TestSize.Level1) unlink(dLog.c_str()); } - HWTEST_F(UpdaterMainUnitTest, updater_main_test_004, TestSize.Level1) { UpdaterUiInit(); @@ -122,25 +124,29 @@ HWTEST_F(UpdaterMainUnitTest, updater_main_test_004, TestSize.Level1) EXPECT_NE(fp, nullptr); UpdateMessage boot {}; - EXPECT_EQ(strncpy_s(boot.command, sizeof(boot.command), "boot_updater", sizeof(boot.command)), 0); - EXPECT_EQ(strncpy_s(boot.update, sizeof(boot.update), - "--update_package=/data/updater/updater.zip\n--retry_count=0", sizeof(boot.update)), 0); + const std::string command1 = "boot_updater"; + EXPECT_EQ(strncpy_s(boot.command, sizeof(boot.command) - 1, command1.c_str(), command1.size()), 0); + const std::string command2 = "--update_package=/data/updater/updater.zip\n--retry_count=0"; + EXPECT_EQ(strncpy_s(boot.update, sizeof(boot.update) - 1, command2.c_str(), command2.size()), 0); bool ret = WriteUpdaterMessage(MISC_FILE, boot); EXPECT_EQ(ret, true); - - int lRet = 0; - int argc = 1; + + int lRet = 0; + int argc = 1; char **argv = new char*[MAX_ARG_SIZE]; argv[0] = new char[10]; + EXPECT_EQ(memset_s(boot.update, sizeof(boot.update), 0, sizeof(boot.update)), 0); - EXPECT_EQ(strncpy_s(boot.update, sizeof(boot.update), "--user_wipe_data", sizeof(boot.update)), 0); + const std::string command3 = "--user_wipe_data"; + EXPECT_EQ(strncpy_s(boot.update, sizeof(boot.update) - 1, command3.c_str(), command3.size()), 0); ret = WriteUpdaterMessage(MISC_FILE, boot); EXPECT_EQ(ret, true); lRet = UpdaterMain(argc, argv); EXPECT_EQ(lRet, 0); EXPECT_EQ(memset_s(boot.update, sizeof(boot.update), 0, sizeof(boot.update)), 0); - EXPECT_EQ(strncpy_s(boot.update, sizeof(boot.update), "--factory_wipe_data", sizeof(boot.update)), 0); + const std::string command4 = "--factory_wipe_data"; + EXPECT_EQ(strncpy_s(boot.update, sizeof(boot.update) - 1, command4.c_str(), command4.size()), 0); ret = WriteUpdaterMessage(MISC_FILE, boot); EXPECT_EQ(ret, true); lRet = UpdaterMain(argc, argv); @@ -154,7 +160,6 @@ HWTEST_F(UpdaterMainUnitTest, updater_main_test_004, TestSize.Level1) DeleteView(); } - HWTEST_F(UpdaterMainUnitTest, updater_main_test_compress, TestSize.Level1) { const std::string testFile = "/data/sdcard/updater/test_compress.txt"; -- Gitee From 3706858785e078d93a907e1c58b95c268d5e9773 Mon Sep 17 00:00:00 2001 From: ma_nan Date: Tue, 28 Sep 2021 17:23:31 +0800 Subject: [PATCH 2/3] fix ut codestyle Signed-off-by: ma_nan --- test/unittest/applypatch_test/all_cmd_unittest.cpp | 4 ++-- test/unittest/applypatch_test/blockset_unittest.cpp | 10 +++++----- test/unittest/applypatch_test/commands_unittest.cpp | 4 ++-- .../unittest/applypatch_test/imagepatch_unittest.cpp | 1 - test/unittest/fs_manager/do_partition_unittest.cpp | 1 - test/unittest/script/script_interpreter_unittest.cpp | 12 ++++++------ 6 files changed, 15 insertions(+), 17 deletions(-) diff --git a/test/unittest/applypatch_test/all_cmd_unittest.cpp b/test/unittest/applypatch_test/all_cmd_unittest.cpp index b4e19a4d..489b5b26 100755 --- a/test/unittest/applypatch_test/all_cmd_unittest.cpp +++ b/test/unittest/applypatch_test/all_cmd_unittest.cpp @@ -98,7 +98,7 @@ bool AllCmdUnitTest::WriteTestBin(int fd, const uint8_t &data, size_t size) cons // new command is not easy to simulate, it depends on // compression and other condition. // Leave new command to be covered by update_image_block test. -HWTEST_F(AllCmdUnitTest, allCmd_test_001,TestSize.Level1) +HWTEST_F(AllCmdUnitTest, allCmd_test_001, TestSize.Level1) { TransferManager *tm = TransferManager::GetTransferManagerInstance(); // Read source @@ -164,7 +164,7 @@ int AllCmdUnitTest::AllCmdUnitTestMove(int &fd, std::vector &allCmd return 0; } -HWTEST_F(AllCmdUnitTest, allCmd_test_002,TestSize.Level1) +HWTEST_F(AllCmdUnitTest, allCmd_test_002, TestSize.Level1) { TransferManagerPtr tm = TransferManager::GetTransferManagerInstance(); std::string filePath = "/tmp/test.bin"; diff --git a/test/unittest/applypatch_test/blockset_unittest.cpp b/test/unittest/applypatch_test/blockset_unittest.cpp index 33144ec0..866765b2 100755 --- a/test/unittest/applypatch_test/blockset_unittest.cpp +++ b/test/unittest/applypatch_test/blockset_unittest.cpp @@ -39,7 +39,7 @@ void BlockSetUnitTest::TearDown(void) cout << "TearDownTestCase" << endl; } -HWTEST_F(BlockSetUnitTest, blockset_test_001,TestSize.Level1) +HWTEST_F(BlockSetUnitTest, blockset_test_001, TestSize.Level1) { cout << "Blockset ut start"; BlockSet block(std::vector {BlockPair{0, 1}}); @@ -66,7 +66,7 @@ HWTEST_F(BlockSetUnitTest, blockset_test_001,TestSize.Level1) EXPECT_EQ(ret, -1); } -HWTEST_F(BlockSetUnitTest, blockset_test_002,TestSize.Level1) +HWTEST_F(BlockSetUnitTest, blockset_test_002, TestSize.Level1) { cout << "Blockset ut two blocks overlap"; BlockSet block(std::vector {BlockPair{0, 1}}); @@ -78,7 +78,7 @@ HWTEST_F(BlockSetUnitTest, blockset_test_002,TestSize.Level1) EXPECT_EQ(ret, false); } -HWTEST_F(BlockSetUnitTest, blockset_test_003,TestSize.Level1) +HWTEST_F(BlockSetUnitTest, blockset_test_003, TestSize.Level1) { cout << "Blockset ut two blocks overlap"; std::vector buffer; @@ -95,7 +95,7 @@ HWTEST_F(BlockSetUnitTest, blockset_test_003,TestSize.Level1) close(fd); } -HWTEST_F(BlockSetUnitTest, blockset_test_004,TestSize.Level1) +HWTEST_F(BlockSetUnitTest, blockset_test_004, TestSize.Level1) { cout << "Blockset ut two blocks overlap"; std::vector srcBuffer; @@ -108,7 +108,7 @@ HWTEST_F(BlockSetUnitTest, blockset_test_004,TestSize.Level1) BlockSet::MoveBlock(srcBuffer, blk, tgtBuffer); } -HWTEST_F(BlockSetUnitTest, blockset_test_005,TestSize.Level1) +HWTEST_F(BlockSetUnitTest, blockset_test_005, TestSize.Level1) { std::string hashValue = "5aa246ebe8e817740f12cc0f6e536c5ea22e5db177563a1caea5a86614275546"; std::string blockInfo = "2,20755,21031 276 2,20306,20582"; diff --git a/test/unittest/applypatch_test/commands_unittest.cpp b/test/unittest/applypatch_test/commands_unittest.cpp index 0b1cf868..22344625 100755 --- a/test/unittest/applypatch_test/commands_unittest.cpp +++ b/test/unittest/applypatch_test/commands_unittest.cpp @@ -49,7 +49,7 @@ void CommandsUnitTest::TearDown() cout << "Updater Unit CommandsUnitTest End!" << endl; } -HWTEST_F(CommandsUnitTest, command_test_001, TestSize.Level1) +HWTEST_F(CommandsUnitTest, command_test_001, TestSize.Level0) { std::string hashValue = "5aa246ebe8e817740f12cc0f6e536c5ea22e5db177563a1caea5a86614275546"; std::string blockInfo = "2,20755,21031 276 2,20306,20582"; @@ -65,7 +65,7 @@ HWTEST_F(CommandsUnitTest, command_test_001, TestSize.Level1) delete cmd; } -HWTEST_F(CommandsUnitTest, command_test_002,TestSize.Level1) +HWTEST_F(CommandsUnitTest, command_test_002,TestSize.Level0) { std::string hashValue = "5aa246ebe8e817740f12cc0f6e536c5ea22e5db177563a1caea5a86614275546"; std::string blockInfo = "2,20755,21031 276 2,20306,20582"; diff --git a/test/unittest/applypatch_test/imagepatch_unittest.cpp b/test/unittest/applypatch_test/imagepatch_unittest.cpp index 0266493a..c9a1466c 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); } - printf("ReadContentFromFile %s %d \n", file.c_str(), n); close(fd); return ((n == 0) ? true : false); } diff --git a/test/unittest/fs_manager/do_partition_unittest.cpp b/test/unittest/fs_manager/do_partition_unittest.cpp index d7cd7998..32c652cb 100755 --- a/test/unittest/fs_manager/do_partition_unittest.cpp +++ b/test/unittest/fs_manager/do_partition_unittest.cpp @@ -117,7 +117,6 @@ HWTEST_F(DoPartitionUnitTest, do_partition_test_001, TestSize.Level1) PartitonList olist; size_t xxxPartitionStart = dataPartitionStart + XXX_PARTITION_LEN; - InitEmmcPartition(myPaty[partitionIndex], "xxxxxx", xxxPartitionStart, XXX_PARTITION_LEN); olist.push_back(&myPaty[partitionIndex]); int ret1 = RegisterUpdaterPartitionList(nList, olist); diff --git a/test/unittest/script/script_interpreter_unittest.cpp b/test/unittest/script/script_interpreter_unittest.cpp index 68e79b53..1f0cc797 100755 --- a/test/unittest/script/script_interpreter_unittest.cpp +++ b/test/unittest/script/script_interpreter_unittest.cpp @@ -192,37 +192,37 @@ protected: void TestBody() {} }; -HWTEST_F(ScriptInterpreterUnitTest, TestScriptInterpreterScriptValue, TestSize.Level1) +HWTEST_F(ScriptInterpreterUnitTest, TestScriptInterpreterScriptValue, TestSize.Level0) { ScriptInterpreterUnitTest test; EXPECT_EQ(0, test.TestScriptInterpreterScriptValue()); } -HWTEST_F(ScriptInterpreterUnitTest, TestScriptInstructionContext, TestSize.Level1) +HWTEST_F(ScriptInterpreterUnitTest, TestScriptInstructionContext, TestSize.Level0) { ScriptInterpreterUnitTest test; EXPECT_EQ(0, test.TestScriptInstructionContext()); } -HWTEST_F(ScriptInterpreterUnitTest, TestIntegerValueComputer, TestSize.Level1) +HWTEST_F(ScriptInterpreterUnitTest, TestIntegerValueComputer, TestSize.Level0) { ScriptInterpreterUnitTest test; EXPECT_EQ(0, test.TestIntegerValueComputer()); } -HWTEST_F(ScriptInterpreterUnitTest, TestFloatValueComputer, TestSize.Level1) +HWTEST_F(ScriptInterpreterUnitTest, TestFloatValueComputer, TestSize.Level0) { ScriptInterpreterUnitTest test; EXPECT_EQ(0, test.TestFloatValueComputer()); } -HWTEST_F(ScriptInterpreterUnitTest, TestStringValueComputer, TestSize.Level1) +HWTEST_F(ScriptInterpreterUnitTest, TestStringValueComputer, TestSize.Level0) { ScriptInterpreterUnitTest test; EXPECT_EQ(0, test.TestStringValueComputer()); } -HWTEST_F(ScriptInterpreterUnitTest, SomeDestructor, TestSize.Level1) +HWTEST_F(ScriptInterpreterUnitTest, SomeDestructor, TestSize.Level0) { IntegerValue a1(0); FloatValue a2(0.0); -- Gitee From 9988832c8f4c5fb3bc4487a7714e6efc3a5a2edd Mon Sep 17 00:00:00 2001 From: ma_nan Date: Tue, 28 Sep 2021 17:26:27 +0800 Subject: [PATCH 3/3] fix ut codestyle Signed-off-by: ma_nan --- test/unittest/applypatch_test/commands_unittest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unittest/applypatch_test/commands_unittest.cpp b/test/unittest/applypatch_test/commands_unittest.cpp index 22344625..809d669b 100755 --- a/test/unittest/applypatch_test/commands_unittest.cpp +++ b/test/unittest/applypatch_test/commands_unittest.cpp @@ -65,7 +65,7 @@ HWTEST_F(CommandsUnitTest, command_test_001, TestSize.Level0) delete cmd; } -HWTEST_F(CommandsUnitTest, command_test_002,TestSize.Level0) +HWTEST_F(CommandsUnitTest, command_test_002, TestSize.Level0) { std::string hashValue = "5aa246ebe8e817740f12cc0f6e536c5ea22e5db177563a1caea5a86614275546"; std::string blockInfo = "2,20755,21031 276 2,20306,20582"; -- Gitee