diff --git a/services/ans/test/unittest/advanced_notification_service_test.cpp b/services/ans/test/unittest/advanced_notification_service_test.cpp index 90ab09a7046236c67e3657227cb3e16ece9ea17e..ce3ac1881ebdaddf4f84ad1b22fe5feff370590b 100644 --- a/services/ans/test/unittest/advanced_notification_service_test.cpp +++ b/services/ans/test/unittest/advanced_notification_service_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 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 @@ -32,6 +32,7 @@ #include "mock_ipc_skeleton.h" #include "notification_preferences.h" #include "notification_subscriber.h" +#include "notification_subscriber_manager.h" #include "mock_push_callback_stub.h" #include "system_event_observer.h" #include "notification_constant.h" @@ -938,9 +939,13 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_08300, { auto subscriber = new TestAnsSubscriber(); sptr info = new NotificationSubscribeInfo(); - EXPECT_EQ((int)advancedNotificationService_->Subscribe(subscriber->GetImpl(), info), (int)ERR_OK); - EXPECT_EQ((int)advancedNotificationService_->Subscribe(nullptr, info), (int)ERR_ANS_INVALID_PARAM); - EXPECT_EQ((int)advancedNotificationService_->Unsubscribe(subscriber->GetImpl(), nullptr), (int)ERR_OK); + sptr advancedNotificationServices = new (std::nothrow) AdvancedNotificationService(); + std::shared_ptr notificationSubscriberManager = + NotificationSubscriberManager::GetInstance(); + notificationSubscriberManager->notificationSubQueue_ = std::make_shared("NotificationSubscriberMgr"); + EXPECT_EQ((int)advancedNotificationServices->Subscribe(subscriber->GetImpl(), info), (int)ERR_OK); + EXPECT_EQ((int)advancedNotificationServices->Subscribe(nullptr, info), (int)ERR_ANS_INVALID_PARAM); + EXPECT_EQ((int)advancedNotificationServices->Unsubscribe(subscriber->GetImpl(), nullptr), (int)ERR_OK); } /** @@ -2532,8 +2537,12 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_17400, auto subscriber = new TestAnsSubscriber(); sptr info = new NotificationSubscribeInfo(); - EXPECT_EQ(advancedNotificationService_->Subscribe(subscriber->GetImpl(), info), ERR_OK); - EXPECT_EQ(advancedNotificationService_->Unsubscribe(subscriber->GetImpl(), info), ERR_OK); + sptr advancedNotificationServices = new (std::nothrow) AdvancedNotificationService(); + std::shared_ptr notificationSubscriberManager = + NotificationSubscriberManager::GetInstance(); + notificationSubscriberManager->notificationSubQueue_ = std::make_shared("NotificationSubscriberMgr"); + EXPECT_EQ(advancedNotificationServices->Subscribe(subscriber->GetImpl(), info), ERR_OK); + EXPECT_EQ(advancedNotificationServices->Unsubscribe(subscriber->GetImpl(), info), ERR_OK); GTEST_LOG_(INFO) << "Subscribe_1000 test end"; } @@ -2550,8 +2559,12 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_17500, auto subscriber = new TestAnsSubscriber(); sptr info = new NotificationSubscribeInfo(); - EXPECT_EQ(advancedNotificationService_->Subscribe(subscriber->GetImpl(), info), ERR_OK); - EXPECT_EQ(advancedNotificationService_->Unsubscribe(nullptr, info), ERR_ANS_INVALID_PARAM); + sptr advancedNotificationServices = new (std::nothrow) AdvancedNotificationService(); + std::shared_ptr notificationSubscriberManager = + NotificationSubscriberManager::GetInstance(); + notificationSubscriberManager->notificationSubQueue_ = std::make_shared("NotificationSubscriberMgr"); + EXPECT_EQ(advancedNotificationServices->Subscribe(subscriber->GetImpl(), info), ERR_OK); + EXPECT_EQ(advancedNotificationServices->Unsubscribe(nullptr, info), ERR_ANS_INVALID_PARAM); GTEST_LOG_(INFO) << "Unsubscribe_1000 test end"; } diff --git a/services/ans/test/unittest/bundle_manager_helper_test.cpp b/services/ans/test/unittest/bundle_manager_helper_test.cpp index 0f45225b00ffddc108c3c2ee9e3397961d51c3b0..01cae17204de544d9e2107cd5a8bdfc25e74124b 100644 --- a/services/ans/test/unittest/bundle_manager_helper_test.cpp +++ b/services/ans/test/unittest/bundle_manager_helper_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 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 @@ -58,7 +58,7 @@ HWTEST_F(BundleManagerHelperTest, BundleManagerHelperTest_00100, Function | Smal */ HWTEST_F(BundleManagerHelperTest, BundleManagerHelperTest_00200, Function | SmallTest | Level1) { - pid_t callingUid = IPCSkeleton::GetCallingUid(); + pid_t callingUid = 100; std::shared_ptr bundleManager = BundleManagerHelper::GetInstance(); EXPECT_TRUE(bundleManager->IsSystemApp(callingUid)); } diff --git a/services/distributed/test/unittest/distributed_database_branch_test/distributed_database_branch_test.cpp b/services/distributed/test/unittest/distributed_database_branch_test/distributed_database_branch_test.cpp index a1b9db645000feee8b25c5709b69af79c28dcab2..45d9d7ee6f1378dfcd6f2bc62116b2c73769226d 100755 --- a/services/distributed/test/unittest/distributed_database_branch_test/distributed_database_branch_test.cpp +++ b/services/distributed/test/unittest/distributed_database_branch_test/distributed_database_branch_test.cpp @@ -512,20 +512,22 @@ HWTEST_F(DistributedDatabaseBranchTest, DistributedDatabaseBranchTest_2900, Func /** * @tc.name : DistributedDatabaseBranchTest_3000 * @tc.number : DistributedDatabaseBranchTest_3000 - * @tc.desc : Test RecreateDistributedDB function and CheckKvDataManager is false. + * @tc.desc : 1.Test RecreateDistributedDB function and CheckKvDataManager is true. + * 2.set KvManagerFlowControl is true + * 3.status is DistributedKv::Status::SUCCESS */ HWTEST_F(DistributedDatabaseBranchTest, DistributedDatabaseBranchTest_3000, Function | SmallTest | Level1) { - std::shared_ptr distributedDatabase = - std::make_shared(databaseCallback_, deviceCallback_); - distributedDatabase->kvDataManager_ = nullptr; - EXPECT_EQ(false, distributedDatabase->RecreateDistributedDB()); + database_->kvDataManager_ = std::make_unique(); + MockKvManagerFlowControl(true); + EXPECT_EQ(true, database_->RecreateDistributedDB()); } /** * @tc.name : DistributedDatabaseBranchTest_3100 * @tc.number : DistributedDatabaseBranchTest_3100 - * @tc.desc : Test RecreateDistributedDB function and KvManagerFlowControl is false. + * @tc.desc : 1.Test RecreateDistributedDB function and CheckKvDataManager is true. + * 2.set KvManagerFlowControl is false */ HWTEST_F(DistributedDatabaseBranchTest, DistributedDatabaseBranchTest_3100, Function | SmallTest | Level1) { diff --git a/services/distributed/test/unittest/distributed_database_branch_test/mock_distributed_kv_data_manager.cpp b/services/distributed/test/unittest/distributed_database_branch_test/mock_distributed_kv_data_manager.cpp index e22aa63a4dec0aec4b97eb57abe31c5e811f2863..be53419968c01d401e1baf896e0729320f531a02 100755 --- a/services/distributed/test/unittest/distributed_database_branch_test/mock_distributed_kv_data_manager.cpp +++ b/services/distributed/test/unittest/distributed_database_branch_test/mock_distributed_kv_data_manager.cpp @@ -60,5 +60,10 @@ Status DistributedKvDataManager::GetSingleKvStore(const Options &options, const } return Status::SUCCESS; } + +Status DistributedKvDataManager::DeleteKvStore(const AppId &appId, const StoreId &storeId, const std::string &path) +{ + return Status::SUCCESS; +} } // namespace DistributedKv } // namespace OHOS \ No newline at end of file