diff --git a/test/unittest/updater_binary/BUILD.gn b/test/unittest/updater_binary/BUILD.gn index 4d152cd706a2df87b30e34f6655d783679fe2914..443aa6506098d9cf651b1fe818b02949d18b5cee 100644 --- a/test/unittest/updater_binary/BUILD.gn +++ b/test/unittest/updater_binary/BUILD.gn @@ -23,6 +23,7 @@ ohos_unittest("binary_unittest") { sources = [ "update_image_block_test.cpp", "update_image_patch_unittest.cpp", + "update_partitions_unittest.cpp", "update_processor_unittest.cpp", ] diff --git a/test/unittest/updater_binary/update_image_block_test.cpp b/test/unittest/updater_binary/update_image_block_test.cpp index e5f1675293da4f65e98017a1e3cd2a63166d64a1..da3294e2bd12f44b8e9e832e776d2fa8295ab252 100755 --- a/test/unittest/updater_binary/update_image_block_test.cpp +++ b/test/unittest/updater_binary/update_image_block_test.cpp @@ -61,10 +61,12 @@ void UpdateImageBlockTest::TearDown() HWTEST_F(UpdateImageBlockTest, update_image_block_test_001, TestSize.Level1) { const string packagePath = "/data/updater/updater/updater_write_miscblock_img.zip"; - int fd = open("/dev/null", O_RDWR); - dup2(fd, STDOUT_FILENO); - int32_t ret = ProcessUpdater(false, STDOUT_FILENO, packagePath, GetTestCertName()); - close(fd); + int pfd[2]; // 2: pipe read, pipe write + int ret = pipe(pfd); + EXPECT_GE(ret, 0); + ret = ProcessUpdater(false, pfd[1], packagePath, GetTestCertName()); + close(pfd[0]); + close(pfd[1]); EXPECT_EQ(ret, 0); } @@ -72,10 +74,12 @@ HWTEST_F(UpdateImageBlockTest, update_image_block_test_001, TestSize.Level1) HWTEST_F(UpdateImageBlockTest, update_image_block_test_002, TestSize.Level1) { const string packagePath = "/data/updater/updater/updater_write_diff_miscblock_img.zip"; - int fd = open("/dev/null", O_RDWR); - dup2(fd, STDOUT_FILENO); - int32_t ret = ProcessUpdater(false, STDOUT_FILENO, packagePath, GetTestCertName()); - close(fd); + int pfd[2]; // 2: pipe read, pipe write + int ret = pipe(pfd); + EXPECT_GE(ret, 0); + ret = ProcessUpdater(false, pfd[1], packagePath, GetTestCertName()); + close(pfd[0]); + close(pfd[1]); EXPECT_EQ(ret, 0); } @@ -83,20 +87,22 @@ HWTEST_F(UpdateImageBlockTest, update_image_block_test_002, TestSize.Level1) HWTEST_F(UpdateImageBlockTest, update_image_block_test_003, TestSize.Level1) { const string packagePath = "/data/updater/updater/updater_write_diff_miscblock_img.zip"; - int fd = open("/dev/null", O_RDWR); - dup2(fd, STDOUT_FILENO); - int32_t ret = ProcessUpdater(false, STDOUT_FILENO, packagePath, GetTestCertName()); - close(fd); + int pfd[2]; // 2: pipe read, pipe write + int ret = pipe(pfd); + EXPECT_GE(ret, 0); + ret = ProcessUpdater(false, pfd[1], packagePath, GetTestCertName()); + close(pfd[0]); + close(pfd[1]); EXPECT_EQ(ret, USCRIPT_INVALID_PARAM); } HWTEST_F(UpdateImageBlockTest, update_image_block_test_004, TestSize.Level1) { const string packagePath = "/data/updater/updater/updater_diff_misc_verify_err.zip"; - int fd = open("/dev/null", O_RDWR); - dup2(fd, STDOUT_FILENO); - int32_t ret = ProcessUpdater(false, STDOUT_FILENO, packagePath, GetTestCertName()); - close(fd); + int pfd[2]; // 2: pipe read, pipe write + int ret = pipe(pfd); + EXPECT_GE(ret, 0); + ret = ProcessUpdater(false, pfd[1], packagePath, GetTestCertName()); EXPECT_NE(ret, 0); } } diff --git a/test/unittest/updater_binary/update_processor_unittest.cpp b/test/unittest/updater_binary/update_processor_unittest.cpp index 583881a5a9b42f6d7f6bb2a568f5f5e019caac35..c223aa5ffa4372ad3546dc176b50b3f2177b079f 100755 --- a/test/unittest/updater_binary/update_processor_unittest.cpp +++ b/test/unittest/updater_binary/update_processor_unittest.cpp @@ -72,10 +72,12 @@ void UpdateProcessorUnitTest::TearDownTestCase(void) {} HWTEST_F(UpdateProcessorUnitTest, UpdateProcessor_001, TestSize.Level1) { const string packagePath = "/data/updater/updater/updater_write_misc_img.zip"; - int fd = open("/dev/null", O_RDWR); - dup2(fd, STDOUT_FILENO); - int32_t ret = ProcessUpdater(false, STDOUT_FILENO, packagePath, GetTestCertName()); - close(fd); + int pfd[2]; // 2: pipe read, pipe write + int ret = pipe(pfd); + EXPECT_GE(ret, 0); + ret = ProcessUpdater(false, pfd[1], packagePath, GetTestCertName()); + close(pfd[0]); + close(pfd[1]); EXPECT_EQ(ret, 0); } @@ -88,10 +90,12 @@ HWTEST_F(UpdateProcessorUnitTest, UpdateProcessor_002, TestSize.Level1) EXPECT_EQ(ret, 0); const string packagePath = "/data/updater/updater/updater_write_diff_misc_img.zip"; - int fd = open("/dev/null", O_RDWR); - dup2(fd, STDOUT_FILENO); - ret = ProcessUpdater(false, STDOUT_FILENO, packagePath, GetTestCertName()); - close(fd); + int pfd[2]; // 2: pipe read, pipe write + ret = pipe(pfd); + EXPECT_GE(ret, 0); + ret = ProcessUpdater(false, pfd[1], packagePath, GetTestCertName()); + close(pfd[0]); + close(pfd[1]); EXPECT_EQ(ret, 0); } @@ -104,10 +108,12 @@ HWTEST_F(UpdateProcessorUnitTest, UpdateProcessor_003, TestSize.Level1) EXPECT_EQ(ret, 0); const string packagePath = "/data/updater/updater/updater_write_diff_misc_img.zip"; - int fd = open("/dev/null", O_RDWR); - dup2(fd, STDOUT_FILENO); - ret = ProcessUpdater(false, STDOUT_FILENO, packagePath, GetTestCertName()); - close(fd); + int pfd[2]; // 2: pipe read, pipe write + ret = pipe(pfd); + EXPECT_GE(ret, 0); + ret = ProcessUpdater(false, pfd[1], packagePath, GetTestCertName()); + close(pfd[0]); + close(pfd[1]); EXPECT_EQ(ret, USCRIPT_INVALID_PARAM); } @@ -141,10 +147,32 @@ HWTEST_F(UpdateProcessorUnitTest, UpdateProcessor_005, TestSize.Level1) HWTEST_F(UpdateProcessorUnitTest, UpdateProcessor_006, TestSize.Level1) { const string packagePath = "/data/updater/updater/updater_write_not_exist.zip"; - int fd = open("/dev/null", O_RDWR); - dup2(fd, STDOUT_FILENO); - int32_t ret = ProcessUpdater(false, STDOUT_FILENO, packagePath, GetTestCertName()); - close(fd); + int pfd[2]; // 2: pipe read, pipe write + int ret = pipe(pfd); + EXPECT_GE(ret, 0); + ret = ProcessUpdater(false, pfd[1], packagePath, GetTestCertName()); + close(pfd[0]); + close(pfd[1]); EXPECT_EQ(ret, EXIT_INVALID_ARGS); } + +HWTEST_F(UpdateProcessorUnitTest, UpdaterEnv_Unitest01, TestSize.Level1) +{ + PkgManager::PkgManagerPtr pkgManager = PkgManager::CreatePackageInstance(); + UpdaterEnv *env = new UpdaterEnv(pkgManager, nullptr, false); + EXPECT_NE(env, nullptr); + env->PostMessage("set_progress", "0.1"); + free(env); + env = nullptr; + + env = new UpdaterEnv(pkgManager, [](const char *cmd, const char *content) {}, false); + EXPECT_NE(env, nullptr); + env->PostMessage("set_progress", "0.1"); + UScriptInstructionFactoryPtr factory = env->GetInstructionFactory(); + factory = env->GetInstructionFactory(); + EXPECT_NE(factory, nullptr); + free(env); + env = nullptr; + PkgManager::ReleasePackageInstance(pkgManager); +} } // namespace updater_ut diff --git a/test/unittest/updaterkits_test/updaterkits_unittest.cpp b/test/unittest/updaterkits_test/updaterkits_unittest.cpp index 45ede9291c63f6714b6cf5701773d4ee0642f09e..7c2252d572db05311e9b56c4de6562be3585c683 100755 --- a/test/unittest/updaterkits_test/updaterkits_unittest.cpp +++ b/test/unittest/updaterkits_test/updaterkits_unittest.cpp @@ -70,7 +70,7 @@ HWTEST_F(UpdaterKitsUnitTest, updater_kits_test02, TestSize.Level1) EXPECT_EQ(ret, true); char testPath[1024] = {0}; // 1024: max len - for (int i = 0; i < sizeof(testPath); i++) { + for (int i = 0; i < sizeof(testPath) - 1; i++) { testPath[i] = 'a'; } pkgPath.push_back(testPath);