diff --git a/frameworks/ans/test/moduletest/ans_fw_module_test.cpp b/frameworks/ans/test/moduletest/ans_fw_module_test.cpp index 5d97a1a1a316651d0af4e03ee9a916c04fcb5a59..5b39ee2df70c8fc759aa4cfb98531c0a6e2ac334 100644 --- a/frameworks/ans/test/moduletest/ans_fw_module_test.cpp +++ b/frameworks/ans/test/moduletest/ans_fw_module_test.cpp @@ -1098,6 +1098,9 @@ inline std::shared_ptr MakePixelMap(int32_t width, int32_t height) { const int32_t PIXEL_BYTES = 4; std::shared_ptr pixelMap = std::make_shared(); + if (pixelMap == nullptr) { + return pixelMap; + } ImageInfo info; info.size.width = width; info.size.height = height; diff --git a/frameworks/ans/test/moduletest/ans_innerkits_module_publish_test.cpp b/frameworks/ans/test/moduletest/ans_innerkits_module_publish_test.cpp index ec2898f5b865c827a00cdc2731099254016a1dda..e82c4e47e9cad6620a46a02d2401f375d3e88c71 100644 --- a/frameworks/ans/test/moduletest/ans_innerkits_module_publish_test.cpp +++ b/frameworks/ans/test/moduletest/ans_innerkits_module_publish_test.cpp @@ -339,7 +339,7 @@ private: EXPECT_EQ(false, notificationRequest.IsAlertOneTime()); EXPECT_EQ(0, notificationRequest.GetAutoDeletedTime()); EXPECT_EQ("classification", notificationRequest.GetClassification()); - EXPECT_EQ(0, notificationRequest.GetColor()); + EXPECT_EQ((uint32_t)0, notificationRequest.GetColor()); } void CheckCaseNineResult(NotificationRequest notificationRequest) @@ -482,12 +482,14 @@ HWTEST_F(AnsInterfaceModulePublishTest, ANS_Interface_MT_Publish_00100, Function EXPECT_EQ(0, NotificationHelper::SubscribeNotification(subscriber, info)); WaitOnSubscribeResult(); std::shared_ptr mediaContent = std::make_shared(); + EXPECT_NE(mediaContent, nullptr); mediaContent->SetAVToken(nullptr); std::vector actions; actions.push_back(0); mediaContent->SetShownActions(actions); GTEST_LOG_(INFO) << "ANS_Interface_MT_Publish_00100::mediaContent:" << mediaContent->Dump(); std::shared_ptr content = std::make_shared(mediaContent); + EXPECT_NE(content, nullptr); GTEST_LOG_(INFO) << "ANS_Interface_MT_Publish_00100::Content:" << content->Dump(); NotificationRequest req; req.SetContent(content); @@ -500,11 +502,13 @@ HWTEST_F(AnsInterfaceModulePublishTest, ANS_Interface_MT_Publish_00100, Function req.SetCreatorBundleName("creatorbundlename"); req.SetLabel("ANS_Interface_MT_Publish_00100"); std::shared_ptr requestPtr = std::make_shared(); + EXPECT_NE(requestPtr, nullptr); requestPtr->SetLabel("ANS_Interface_MT_Publish_00100_REQUEST"); req.SetPublicNotification(requestPtr); // pixelmap auto pixelMap = std::make_shared(); + EXPECT_NE(pixelMap, nullptr); Media::ImageInfo imageInfo; imageInfo.size.width = PIXEL_MAP_TEST_WIDTH; imageInfo.size.height = PIXEL_MAP_TEST_HEIGHT; @@ -522,6 +526,7 @@ HWTEST_F(AnsInterfaceModulePublishTest, ANS_Interface_MT_Publish_00100, Function req.SetBigIcon(pixelMap); req.SetLittleIcon(pixelMap); std::shared_ptr messageUserPtr = std::make_shared(); + EXPECT_NE(messageUserPtr, nullptr); messageUserPtr->SetName("ANS_Interface_MT_Publish_00100_Message_User"); messageUserPtr->SetKey("key"); messageUserPtr->SetPixelMap(nullptr); @@ -558,7 +563,9 @@ HWTEST_F(AnsInterfaceModulePublishTest, ANS_Interface_MT_Publish_00200, Function EXPECT_EQ(0, NotificationHelper::SubscribeNotification(subscriber, info)); WaitOnSubscribeResult(); std::shared_ptr mediaContent = std::make_shared(); + EXPECT_NE(mediaContent, nullptr); std::shared_ptr content = std::make_shared(mediaContent); + EXPECT_NE(content, nullptr); WantAgent::WantAgentInfo paramsInfo; std::shared_ptr wantAgent = WantAgent::WantAgentHelper::GetWantAgent(paramsInfo); std::shared_ptr actionButton = @@ -615,7 +622,9 @@ HWTEST_F(AnsInterfaceModulePublishTest, ANS_Interface_MT_Publish_00300, Function EXPECT_EQ(0, NotificationHelper::SubscribeNotification(subscriber, info)); WaitOnSubscribeResult(); std::shared_ptr mediaContent = std::make_shared(); + EXPECT_NE(mediaContent, nullptr); std::shared_ptr content = std::make_shared(mediaContent); + EXPECT_NE(content, nullptr); WantAgent::WantAgentInfo paramsInfo; std::shared_ptr wantAgent = WantAgent::WantAgentHelper::GetWantAgent(paramsInfo); if (nullptr == wantAgent) { @@ -672,14 +681,17 @@ HWTEST_F(AnsInterfaceModulePublishTest, ANS_Interface_MT_Publish_00400, Function GTEST_LOG_(INFO) << "ANS_Interface_MT_Publish_00400::messgaeUser is::" << messageUser.Dump(); std::shared_ptr conversationContent = std::make_shared(messageUser); + EXPECT_NE(conversationContent, nullptr); conversationContent->SetConversationTitle("ConversationTitle"); conversationContent->SetConversationGroup(false); conversationContent->AddConversationalMessage("text", 0, sender); std::shared_ptr messagePtr = std::make_shared("messageptr", 0, sender); + EXPECT_NE(messagePtr, nullptr); conversationContent->AddConversationalMessage(messagePtr); GTEST_LOG_(INFO) << "ANS_Interface_MT_Publish_00400::conversationContent is::" << conversationContent->Dump(); std::shared_ptr content = std::make_shared(conversationContent); + EXPECT_NE(content, nullptr); NotificationRequest req; req.SetContent(content); req.SetSlotType(NotificationConstant::OTHER); @@ -710,11 +722,13 @@ HWTEST_F(AnsInterfaceModulePublishTest, ANS_Interface_MT_Publish_00500, Function WaitOnSubscribeResult(); MessageUser messageUser; std::shared_ptr multiLineContent = std::make_shared(); + EXPECT_NE(multiLineContent, nullptr); multiLineContent->SetExpandedTitle("expandedtitle"); multiLineContent->SetBriefText("brieftext"); multiLineContent->AddSingleLine("singleLine"); GTEST_LOG_(INFO) << "ANS_Interface_MT_Publish_00500::multiLineContent::" << multiLineContent->Dump(); std::shared_ptr content = std::make_shared(multiLineContent); + EXPECT_NE(content, nullptr); NotificationRequest req; req.SetContent(content); req.SetSlotType(NotificationConstant::OTHER); @@ -745,11 +759,13 @@ HWTEST_F(AnsInterfaceModulePublishTest, ANS_Interface_MT_Publish_00600, Function WaitOnSubscribeResult(); MessageUser messageUser; std::shared_ptr pictureContent = std::make_shared(); + EXPECT_NE(pictureContent, nullptr); pictureContent->SetExpandedTitle("expendedtitle"); pictureContent->SetBriefText("brieftext"); pictureContent->SetBigPicture(nullptr); GTEST_LOG_(INFO) << "ANS_Interface_MT_Publish_00600::pictureContent is::" << pictureContent->Dump(); std::shared_ptr content = std::make_shared(pictureContent); + EXPECT_NE(content, nullptr); NotificationRequest req; req.SetContent(content); req.SetSlotType(NotificationConstant::OTHER); @@ -781,11 +797,13 @@ HWTEST_F(AnsInterfaceModulePublishTest, ANS_Interface_MT_Publish_00700, Function MessageUser messageUser; std::shared_ptr longTextContent = std::make_shared("longtext"); + EXPECT_NE(longTextContent, nullptr); longTextContent->SetExpandedTitle("expendedtitle"); longTextContent->SetBriefText("brieftext"); longTextContent->SetLongText("longtext"); GTEST_LOG_(INFO) << "ANS_Interface_MT_Publish_00700::longTextContentis::" << longTextContent->Dump(); std::shared_ptr content = std::make_shared(longTextContent); + EXPECT_NE(content, nullptr); NotificationRequest req; req.SetContent(content); req.SetSlotType(NotificationConstant::OTHER); @@ -815,8 +833,10 @@ HWTEST_F(AnsInterfaceModulePublishTest, ANS_Interface_MT_Publish_00800, Function WaitOnSubscribeResult(); MessageUser messageUser; std::shared_ptr normalContent = std::make_shared(); + EXPECT_NE(normalContent, nullptr); GTEST_LOG_(INFO) << "ANS_Interface_MT_Publish_00800::normalContentis::" << normalContent->Dump(); std::shared_ptr content = std::make_shared(normalContent); + EXPECT_NE(content, nullptr); NotificationRequest req; req.SetContent(content); req.SetSlotType(NotificationConstant::CONTENT_INFORMATION); @@ -856,7 +876,9 @@ HWTEST_F(AnsInterfaceModulePublishTest, ANS_Interface_MT_Publish_00900, Function WaitOnSubscribeResult(); MessageUser messageUser; std::shared_ptr normalContent = std::make_shared(); + EXPECT_NE(normalContent, nullptr); std::shared_ptr content = std::make_shared(normalContent); + EXPECT_NE(content, nullptr); NotificationRequest req; req.SetContent(content); req.SetSlotType(NotificationConstant::OTHER); @@ -901,7 +923,9 @@ HWTEST_F(AnsInterfaceModulePublishTest, ANS_Interface_MT_Publish_01000, Function WaitOnSubscribeResult(); MessageUser messageUser; std::shared_ptr normalContent = std::make_shared(); + EXPECT_NE(normalContent, nullptr); std::shared_ptr content = std::make_shared(normalContent); + EXPECT_NE(content, nullptr); NotificationRequest req; req.SetContent(content); req.SetSlotType(NotificationConstant::SERVICE_REMINDER); @@ -932,7 +956,9 @@ HWTEST_F(AnsInterfaceModulePublishTest, ANS_Interface_MT_Publish_02000, Function WaitOnSubscribeResult(); MessageUser messageUser; std::shared_ptr normalContent = std::make_shared(); + EXPECT_NE(normalContent, nullptr); std::shared_ptr content = std::make_shared(normalContent); + EXPECT_NE(content, nullptr); NotificationRequest req; req.SetContent(content); req.SetSlotType(NotificationConstant::SOCIAL_COMMUNICATION); @@ -962,7 +988,9 @@ HWTEST_F(AnsInterfaceModulePublishTest, ANS_Interface_MT_Publish_03000, Function WaitOnSubscribeResult(); MessageUser messageUser; std::shared_ptr normalContent = std::make_shared(); + EXPECT_NE(normalContent, nullptr); std::shared_ptr content = std::make_shared(normalContent); + EXPECT_NE(content, nullptr); NotificationRequest req; req.SetContent(content); req.SetSlotType(NotificationConstant::CUSTOM); @@ -995,7 +1023,9 @@ HWTEST_F(AnsInterfaceModulePublishTest, ANS_Interface_MT_Publish_04000, Function EXPECT_EQ(0, NotificationHelper::SetDisturbMode(NotificationConstant::ALLOW_ALARMS)); MessageUser messageUser; std::shared_ptr normalContent = std::make_shared(); + EXPECT_NE(normalContent, nullptr); std::shared_ptr content = std::make_shared(normalContent); + EXPECT_NE(content, nullptr); NotificationRequest req; req.SetContent(content); req.SetSlotType(NotificationConstant::SOCIAL_COMMUNICATION); @@ -1028,7 +1058,9 @@ HWTEST_F(AnsInterfaceModulePublishTest, ANS_Interface_MT_Publish_05000, Function EXPECT_EQ(0, NotificationHelper::SetDisturbMode(NotificationConstant::ALLOW_ALL)); MessageUser messageUser; std::shared_ptr normalContent = std::make_shared(); + EXPECT_NE(normalContent, nullptr); std::shared_ptr content = std::make_shared(normalContent); + EXPECT_NE(content, nullptr); NotificationRequest req; req.SetContent(content); req.SetSlotType(NotificationConstant::SOCIAL_COMMUNICATION); @@ -1062,7 +1094,9 @@ HWTEST_F(AnsInterfaceModulePublishTest, ANS_Interface_MT_Publish_06000, Function EXPECT_EQ(0, NotificationHelper::SetDisturbMode(NotificationConstant::ALLOW_NONE)); MessageUser messageUser; std::shared_ptr normalContent = std::make_shared(); + EXPECT_NE(normalContent, nullptr); std::shared_ptr content = std::make_shared(normalContent); + EXPECT_NE(content, nullptr); NotificationRequest req; req.SetContent(content); req.SetSlotType(NotificationConstant::SOCIAL_COMMUNICATION); @@ -1093,7 +1127,9 @@ HWTEST_F(AnsInterfaceModulePublishTest, ANS_Interface_MT_Publish_07000, Function WaitOnSubscribeResult(); MessageUser messageUser; std::shared_ptr normalContent = std::make_shared(); + EXPECT_NE(normalContent, nullptr); std::shared_ptr content = std::make_shared(normalContent); + EXPECT_NE(content, nullptr); NotificationRequest req; req.SetContent(content); req.SetSlotType(NotificationConstant::SOCIAL_COMMUNICATION); @@ -1125,7 +1161,9 @@ HWTEST_F(AnsInterfaceModulePublishTest, ANS_Interface_MT_GetActiveNotifications_ EXPECT_EQ(0, NotificationHelper::SubscribeNotification(subscriber, info)); WaitOnSubscribeResult(); std::shared_ptr implContent = std::make_shared(); + EXPECT_NE(implContent, nullptr); std::shared_ptr content = std::make_shared(implContent); + EXPECT_NE(content, nullptr); EXPECT_EQ((int)ERR_OK, (int)NotificationHelper::CancelAllNotifications()); sleep(SLEEP_TIME); EXPECT_EQ(OnCanceledReceived, true); diff --git a/interfaces/kits/napi/ans/src/common.cpp b/interfaces/kits/napi/ans/src/common.cpp index e57a617a8ca39f8196e0abe0572a578159626af8..a73195283ec68cbcd0372cb6f69c3f8d7da7bd5a 100644 --- a/interfaces/kits/napi/ans/src/common.cpp +++ b/interfaces/kits/napi/ans/src/common.cpp @@ -1905,6 +1905,7 @@ napi_value GetNotificationLongTextContent(const napi_env &env, const napi_value napi_value basicContentResult = nullptr; bool hasProperty = false; char str[STR_MAX_SIZE] = {0}; + char long_str[LONG_STR_MAX_SIZE + 1] = {0}; size_t strLen = 0; NAPI_CALL(env, napi_has_named_property(env, result, "longText", &hasProperty)); @@ -1966,9 +1967,9 @@ napi_value GetNotificationLongTextContent(const napi_env &env, const napi_value napi_get_named_property(env, contentResult, "longText", &longContentResult); NAPI_CALL(env, napi_typeof(env, longContentResult, &valuetype)); NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected."); - NAPI_CALL(env, napi_get_value_string_utf8(env, longContentResult, str, LONG_STR_MAX_SIZE - 1, &strLen)); - longContent->SetLongText(str); - ANS_LOGI("longText::longText = %{public}s", str); + NAPI_CALL(env, napi_get_value_string_utf8(env, longContentResult, long_str, LONG_STR_MAX_SIZE, &strLen)); + longContent->SetLongText(long_str); + ANS_LOGI("longText::longText = %{public}s", long_str); } else { ANS_LOGE("Property longText expected."); return nullptr; diff --git a/interfaces/kits/napi/ans/src/subscribe.cpp b/interfaces/kits/napi/ans/src/subscribe.cpp index 724acd30cf781db619f73859b346e4887151de7d..74d6671e8008b8f0f0b6e3a4e0cfe58da3d5783a 100644 --- a/interfaces/kits/napi/ans/src/subscribe.cpp +++ b/interfaces/kits/napi/ans/src/subscribe.cpp @@ -165,9 +165,11 @@ void SubscriberInstance::OnCanceled(const std::shared_ptr= 2 napi_get_uv_event_loop(canceCallbackInfo_.env, &loop); -#endif // NAPI_VERSION >= 2 + if (loop == nullptr) { + ANS_LOGE("loop instance is nullptr"); + return; + } NotificationReceiveDataWorker *dataWorker = new (std::nothrow) NotificationReceiveDataWorker(); if (dataWorker == nullptr) { @@ -253,9 +255,11 @@ void SubscriberInstance::OnConsumed(const std::shared_ptrGetKey().size()); uv_loop_s *loop = nullptr; -#if NAPI_VERSION >= 2 napi_get_uv_event_loop(consumeCallbackInfo_.env, &loop); -#endif // NAPI_VERSION >= 2 + if (loop == nullptr) { + ANS_LOGE("loop instance is nullptr"); + return; + } NotificationReceiveDataWorker *dataWorker = new (std::nothrow) NotificationReceiveDataWorker(); if (dataWorker == nullptr) { @@ -330,9 +334,11 @@ void SubscriberInstance::OnUpdate(const std::shared_ptr ANS_LOGI("OnUpdate sortingMap size = %{public}zu", sortingMap->GetKey().size()); uv_loop_s *loop = nullptr; -#if NAPI_VERSION >= 2 napi_get_uv_event_loop(updateCallbackInfo_.env, &loop); -#endif // NAPI_VERSION >= 2 + if (loop == nullptr) { + ANS_LOGE("loop instance is nullptr"); + return; + } NotificationReceiveDataWorker *dataWorker = new (std::nothrow) NotificationReceiveDataWorker(); if (dataWorker == nullptr) { @@ -397,9 +403,11 @@ void SubscriberInstance::OnSubscribeResult(NotificationConstant::SubscribeResult ANS_LOGI("OnSubscribeResult result = %{public}d", result); uv_loop_s *loop = nullptr; -#if NAPI_VERSION >= 2 napi_get_uv_event_loop(subscribeCallbackInfo_.env, &loop); -#endif // NAPI_VERSION >= 2 + if (loop == nullptr) { + ANS_LOGE("loop instance is nullptr"); + return; + } NotificationReceiveDataWorker *dataWorker = new (std::nothrow) NotificationReceiveDataWorker(); if (dataWorker == nullptr) { @@ -459,9 +467,11 @@ void SubscriberInstance::OnUnsubscribeResult(NotificationConstant::SubscribeResu ANS_LOGI("OnUnsubscribeResult result = %{public}d", result); uv_loop_s *loop = nullptr; -#if NAPI_VERSION >= 2 napi_get_uv_event_loop(unsubscribeCallbackInfo_.env, &loop); -#endif // NAPI_VERSION >= 2 + if (loop == nullptr) { + ANS_LOGE("loop instance is nullptr"); + return; + } NotificationReceiveDataWorker *dataWorker = new (std::nothrow) NotificationReceiveDataWorker(); if (dataWorker == nullptr) { @@ -523,9 +533,11 @@ void SubscriberInstance::OnDied() } uv_loop_s *loop = nullptr; -#if NAPI_VERSION >= 2 napi_get_uv_event_loop(dieCallbackInfo_.env, &loop); -#endif // NAPI_VERSION >= 2 + if (loop == nullptr) { + ANS_LOGE("loop instance is nullptr"); + return; + } NotificationReceiveDataWorker *dataWorker = new (std::nothrow) NotificationReceiveDataWorker(); if (dataWorker == nullptr) { @@ -582,9 +594,11 @@ void SubscriberInstance::OnDisturbModeChanged(int disturbMode) ANS_LOGI("OnDisturbModeChanged disturbMode = %{public}d", disturbMode); uv_loop_s *loop = nullptr; -#if NAPI_VERSION >= 2 napi_get_uv_event_loop(disturbModeCallbackInfo_.env, &loop); -#endif // NAPI_VERSION >= 2 + if (loop == nullptr) { + ANS_LOGE("loop instance is nullptr"); + return; + } NotificationReceiveDataWorker *dataWorker = new (std::nothrow) NotificationReceiveDataWorker(); if (dataWorker == nullptr) {