From 1c328cbf8168377f54288c45c3ec088e51d5eeee Mon Sep 17 00:00:00 2001 From: huaqingsimeng <1004904143@qq.com> Date: Thu, 20 Apr 2023 16:15:42 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=87=E4=BB=BD=E6=81=A2=E5=A4=8DTDD?= =?UTF-8?q?=E7=94=A8=E4=BE=8B=E8=B0=83=E6=95=B4=E5=A2=9E=E5=8A=A0=E6=96=AD?= =?UTF-8?q?=E8=A8=80=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: huaqingsimeng --- .../backup_impl/svc_death_recipient_test.cpp | 12 ++++++++++++ .../backup_utils/b_filesystem/b_file_test.cpp | 8 +++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/tests/unittests/backup_api/backup_impl/svc_death_recipient_test.cpp b/tests/unittests/backup_api/backup_impl/svc_death_recipient_test.cpp index 27cca4655..a1b1e58eb 100644 --- a/tests/unittests/backup_api/backup_impl/svc_death_recipient_test.cpp +++ b/tests/unittests/backup_api/backup_impl/svc_death_recipient_test.cpp @@ -13,7 +13,9 @@ * limitations under the License. */ +#include #include + #include #include "iservice_registry.h" @@ -25,6 +27,8 @@ using namespace std; using namespace testing; const string FILE_NAME = "temp.json"; +static condition_variable g_cv; +static atomic g_serviceDie = false; class SvcDeathRecipientTest : public testing::Test { public: @@ -32,10 +36,15 @@ public: static void TearDownTestCase() {}; void SetUp() override {}; void TearDown() override {}; + +public: + mutex lock_; }; static void CallBack(const wptr &obj) { + g_serviceDie.store(true); + g_cv.notify_all(); GTEST_LOG_(INFO) << "SvcSessionManagerTest-CallBack success"; } @@ -57,6 +66,9 @@ HWTEST_F(SvcDeathRecipientTest, SUB_backup_sa_deathecipient_OnRemoteDied_0100, t deathRecipient->OnRemoteDied(remote); remote = nullptr; deathRecipient = nullptr; + unique_lock lk(lock_); + g_cv.wait(lk, [&] { return true; }); + ASSERT_TRUE(g_serviceDie); GTEST_LOG_(INFO) << "SvcSessionManagerTest-end SUB_backup_sa_deathecipient_OnRemoteDied_0100"; } } // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/tests/unittests/backup_utils/b_filesystem/b_file_test.cpp b/tests/unittests/backup_utils/b_filesystem/b_file_test.cpp index 22b7c54bf..813e72c0c 100644 --- a/tests/unittests/backup_utils/b_filesystem/b_file_test.cpp +++ b/tests/unittests/backup_utils/b_filesystem/b_file_test.cpp @@ -93,9 +93,11 @@ HWTEST_F(BFileTest, b_file_SendFile_0100, testing::ext::TestSize.Level1) TestManager tm(__func__); const auto [filePath, content] = GetTestFile(tm); TestManager tmInFile("b_file_GetFd_0100"); - string fileInPath = tmInFile.GetRootDirCurTest().append("1.tar"); - BFile::SendFile(UniqueFd(open(filePath.data(), O_RDWR)), - UniqueFd(open(fileInPath.data(), O_RDWR | O_CREAT, S_IRWXU))); + string fileOutPath = tmInFile.GetRootDirCurTest().append("1.tar"); + BFile::SendFile(UniqueFd(open(fileOutPath.data(), O_RDWR)), + UniqueFd(open(filePath.data(), O_RDWR | O_CREAT, S_IRWXU))); + string contentTmp = BFile::ReadFile(UniqueFd(open(fileOutPath.c_str(), O_RDONLY))).get(); + EXPECT_EQ(contentTmp, content); } catch (const exception &e) { GTEST_LOG_(INFO) << "BFileTest-an exception occurred by SendFile."; e.what(); -- Gitee