From 98019f9dd2d8f739d7b232d95732f82f790557d3 Mon Sep 17 00:00:00 2001 From: liqiang Date: Wed, 16 Feb 2022 15:38:06 +0800 Subject: [PATCH] IssueNo:https://gitee.com/openharmony/notification_ans_standard/issues/I4TY28 Description:sync code to weekly branch-fix tdd bug Sig: SIG_ApplicationFramework Feature or Bugfix:Bugfix Binary Source:No Signed-off-by: liqiang Change-Id: I028c402fe7d2ea1d7c08b4977ae7fa6c32779171 --- .../test/unittest/pending_want_test/BUILD.gn | 1 + .../pending_want_test/pending_want_test.cpp | 22 ++++--------------- .../unittest/want_agent_helper_test/BUILD.gn | 1 + .../want_agent_helper_test.cpp | 11 +++++----- .../ans/src/advanced_notification_service.cpp | 7 +----- .../notification_preferences_test.cpp | 3 ++- 6 files changed, 15 insertions(+), 30 deletions(-) diff --git a/frameworks/wantagent/test/unittest/pending_want_test/BUILD.gn b/frameworks/wantagent/test/unittest/pending_want_test/BUILD.gn index 395618932..80252d5fd 100644 --- a/frameworks/wantagent/test/unittest/pending_want_test/BUILD.gn +++ b/frameworks/wantagent/test/unittest/pending_want_test/BUILD.gn @@ -20,6 +20,7 @@ module_output_path = "ans_standard/wantagent" ohos_unittest("pending_want_test") { module_out_path = module_output_path include_dirs = [ + "//aafwk/standard/frameworks/kits/appkit/native/ability_runtime/context/", "//foundation/aafwk/standard/frameworks/kits/appkit/native/ability_runtime", "//foundation/aafwk/standard/services/abilitymgr/include", "//foundation/distributedschedule/samgr/adapter/interfaces/innerkits/include/", diff --git a/frameworks/wantagent/test/unittest/pending_want_test/pending_want_test.cpp b/frameworks/wantagent/test/unittest/pending_want_test/pending_want_test.cpp index 4f66a28dc..ee49efd40 100644 --- a/frameworks/wantagent/test/unittest/pending_want_test/pending_want_test.cpp +++ b/frameworks/wantagent/test/unittest/pending_want_test/pending_want_test.cpp @@ -20,6 +20,7 @@ #include "completed_dispatcher.h" #include "context/context.h" #include "context_container.h" +#include "context_impl.h" #include "element_name.h" #include "event_handler.h" #include "iservice_registry.h" @@ -102,7 +103,8 @@ Want PendingWantTest::MakeWant(std::string deviceId, std::string abilityName, st std::shared_ptr GetAppContext() { - return OHOS::AbilityRuntime::Context::GetApplicationContext(); + std::shared_ptr context = std::make_shared(); + return context; } void PendingWantTest::SetUpTestCase(void) @@ -170,26 +172,10 @@ HWTEST_F(PendingWantTest, PendingWant_0400, Function | MediumTest | Level1) want->SetElement(element); unsigned int flags = 1; flags |= FLAG_NO_CREATE; - std::shared_ptr pendingWant = PendingWant::GetAbility(GetAppContext(), requestCode, want, flags); + std::shared_ptr pendingWant = PendingWant::GetAbility(nullptr, requestCode, want, flags); EXPECT_EQ(pendingWant, nullptr); } -/* - * @tc.number : PendingWant_0500 - * @tc.name : PendingWant GetAbility - * @tc.desc : 1.Get pendingWant (START_ABILITY) - */ -HWTEST_F(PendingWantTest, PendingWant_0500, Function | MediumTest | Level1) -{ - int requestCode = 10; - std::shared_ptr want = std::make_shared(); - ElementName element("device", "bundleName", "abilityName"); - want->SetElement(element); - unsigned int flags = 1; - flags |= FLAG_NO_CREATE; - std::shared_ptr pendingWant = PendingWant::GetAbility(GetAppContext(), requestCode, want, flags); - EXPECT_NE(pendingWant, nullptr); -} /* * @tc.number : PendingWant_0600 diff --git a/frameworks/wantagent/test/unittest/want_agent_helper_test/BUILD.gn b/frameworks/wantagent/test/unittest/want_agent_helper_test/BUILD.gn index 12ec08065..926b3dcf1 100644 --- a/frameworks/wantagent/test/unittest/want_agent_helper_test/BUILD.gn +++ b/frameworks/wantagent/test/unittest/want_agent_helper_test/BUILD.gn @@ -20,6 +20,7 @@ module_output_path = "ans_standard/wantagent" ohos_unittest("want_agent_helper_test") { module_out_path = module_output_path include_dirs = [ + "//aafwk/standard/frameworks/kits/appkit/native/ability_runtime/context/", "//foundation/aafwk/standard/frameworks/kits/appkit/native/ability_runtime", "//foundation/aafwk/standard/services/abilitymgr/include", ] diff --git a/frameworks/wantagent/test/unittest/want_agent_helper_test/want_agent_helper_test.cpp b/frameworks/wantagent/test/unittest/want_agent_helper_test/want_agent_helper_test.cpp index f555062ad..622c8c8b4 100644 --- a/frameworks/wantagent/test/unittest/want_agent_helper_test/want_agent_helper_test.cpp +++ b/frameworks/wantagent/test/unittest/want_agent_helper_test/want_agent_helper_test.cpp @@ -17,6 +17,7 @@ #include "ability_context.h" #include "completed_callback.h" #include "context_container.h" +#include "context_impl.h" #include "context/context.h" #include "element_name.h" #include "event_handler.h" @@ -249,7 +250,7 @@ HWTEST_F(WantAgentHelperTest, WantAgentHelper_1100, Function | MediumTest | Leve HWTEST_F(WantAgentHelperTest, WantAgentHelper_1200, Function | MediumTest | Level1) { std::shared_ptr wantAgentHelper = std::make_shared(); - std::shared_ptr context = OHOS::AbilityRuntime::Context::GetApplicationContext(); + std::shared_ptr context = std::make_shared(); std::shared_ptr want = std::make_shared(); ElementName element("device", "bundleName", "abilityName"); want->SetElement(element); @@ -273,7 +274,7 @@ HWTEST_F(WantAgentHelperTest, WantAgentHelper_1200, Function | MediumTest | Leve HWTEST_F(WantAgentHelperTest, WantAgentHelper_1300, Function | MediumTest | Level1) { std::shared_ptr wantAgentHelper = std::make_shared(); - std::shared_ptr context = OHOS::AbilityRuntime::Context::GetApplicationContext(); + std::shared_ptr context = std::make_shared(); std::shared_ptr want = std::make_shared(); ElementName element("device", "bundleName", "abilityName"); want->SetElement(element); @@ -297,7 +298,7 @@ HWTEST_F(WantAgentHelperTest, WantAgentHelper_1300, Function | MediumTest | Leve HWTEST_F(WantAgentHelperTest, WantAgentHelper_1400, Function | MediumTest | Level1) { std::shared_ptr wantAgentHelper = std::make_shared(); - std::shared_ptr context = OHOS::AbilityRuntime::Context::GetApplicationContext(); + std::shared_ptr context = std::make_shared(); std::shared_ptr want = std::make_shared(); ElementName element("device", "bundleName", "abilityName"); want->SetElement(element); @@ -321,7 +322,7 @@ HWTEST_F(WantAgentHelperTest, WantAgentHelper_1400, Function | MediumTest | Leve HWTEST_F(WantAgentHelperTest, WantAgentHelper_1500, Function | MediumTest | Level1) { std::shared_ptr wantAgentHelper = std::make_shared(); - std::shared_ptr context = OHOS::AbilityRuntime::Context::GetApplicationContext(); + std::shared_ptr context = std::make_shared(); std::shared_ptr want = std::make_shared(); ElementName element("device", "bundleName", "abilityName"); want->SetElement(element); @@ -345,7 +346,7 @@ HWTEST_F(WantAgentHelperTest, WantAgentHelper_1500, Function | MediumTest | Leve HWTEST_F(WantAgentHelperTest, WantAgentHelper_1600, Function | MediumTest | Level1) { std::shared_ptr wantAgentHelper = std::make_shared(); - std::shared_ptr context = OHOS::AbilityRuntime::Context::GetApplicationContext(); + std::shared_ptr context = std::make_shared(); std::shared_ptr want = std::make_shared(); ElementName element("device", "bundleName", "abilityName"); want->SetElement(element); diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index ec56db5b7..d6dfc6c6c 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -1295,16 +1295,11 @@ ErrCode AdvancedNotificationService::GetAllActiveNotifications(std::vectorPostSyncTask(std::bind([&]() { notifications.clear(); for (auto record : notificationList_) { - if (record->notification != nullptr && record->notification->GetUserId() == userId) { + if (record->notification != nullptr) { notifications.push_back(record->notification); } } diff --git a/services/ans/test/unittest/notification_preferences_test.cpp b/services/ans/test/unittest/notification_preferences_test.cpp index fa283597a..df7a67ff1 100644 --- a/services/ans/test/unittest/notification_preferences_test.cpp +++ b/services/ans/test/unittest/notification_preferences_test.cpp @@ -1089,7 +1089,8 @@ HWTEST_F(NotificationPreferencesTest, GetNotificationsEnabled_00200, Function | EXPECT_TRUE(enable); enable = false; - EXPECT_EQ((int)NotificationPreferences::GetInstance().GetNotificationsEnabled(101, enable), (int)ERR_OK); + EXPECT_EQ( + (int)NotificationPreferences::GetInstance().GetNotificationsEnabled(101, enable), (int)ERR_ANS_INVALID_PARAM); EXPECT_FALSE(enable); } -- Gitee