From 6f4716a5aaa68d9c5569fc45b7d8a3aff3cc9380 Mon Sep 17 00:00:00 2001 From: yangjun Date: Mon, 31 Mar 2025 22:45:29 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A5=E5=85=85TDD=E8=A6=86=E7=9B=96?= =?UTF-8?q?=E7=8E=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yangjun Change-Id: I0f6d470c020eeea9dcd68d6142d38cb02faf03aa Signed-off-by: yangjun --- .../include/advanced_notification_service.h | 2 +- ...dvanced_notification_live_view_service.cpp | 7 +- services/ans/test/unittest/BUILD.gn | 1 + ...ed_notification_live_view_service_test.cpp | 422 ++++++++++++++++++ .../distributed_device_status_test.cpp | 107 +++++ 5 files changed, 535 insertions(+), 4 deletions(-) create mode 100644 services/ans/test/unittest/distributed_device_status_test.cpp diff --git a/services/ans/include/advanced_notification_service.h b/services/ans/include/advanced_notification_service.h index 7ead58d2d..3d33ea5e0 100644 --- a/services/ans/include/advanced_notification_service.h +++ b/services/ans/include/advanced_notification_service.h @@ -1364,7 +1364,7 @@ private: ErrCode GetCommonTargetRecordList(const int32_t uid, NotificationConstant::SlotType slotType, NotificationContent::Type contentType, std::vector>& recordList); ErrCode RemoveNotificationFromRecordList(const std::vector>& recordList); - void OnSubscriberAdd(const std::shared_ptr &record); + ErrCode OnSubscriberAdd(const std::shared_ptr &record); bool IsLiveViewCanRecover(const sptr request); ErrCode FillNotificationRecord(const NotificationRequestDb &requestdbObj, std::shared_ptr record); diff --git a/services/ans/src/advanced_notification_live_view_service.cpp b/services/ans/src/advanced_notification_live_view_service.cpp index eb8f7c752..55e622acb 100644 --- a/services/ans/src/advanced_notification_live_view_service.cpp +++ b/services/ans/src/advanced_notification_live_view_service.cpp @@ -167,12 +167,12 @@ void AdvancedNotificationService::ProcForDeleteLiveView(const std::shared_ptr &record) { if (record == nullptr) { ANS_LOGE("No subscriber to notify."); - return; + return ERR_ANS_INVALID_PARAM; } sptr sortingMap = GenerateSortingMap(); @@ -187,11 +187,12 @@ void AdvancedNotificationService::OnSubscriberAdd( if (notifications.empty()) { ANS_LOGI("No notification to consume."); - return; + return ERR_ANS_NOTIFICATION_NOT_EXISTS; } ANS_LOGI("Consume notification count is %{public}zu.", notifications.size()); NotificationSubscriberManager::GetInstance()->BatchNotifyConsumed(notifications, sortingMap, record); + return ERR_OK; } bool AdvancedNotificationService::IsLiveViewCanRecover(const sptr request) diff --git a/services/ans/test/unittest/BUILD.gn b/services/ans/test/unittest/BUILD.gn index ee1c3192e..bcf559699 100644 --- a/services/ans/test/unittest/BUILD.gn +++ b/services/ans/test/unittest/BUILD.gn @@ -1415,6 +1415,7 @@ ohos_unittest("advanced_notification_service_unit_test") { sources = [ "${test_path}/mock/mock_tokenid_kit.cpp", "advanced_notification_service_test/advanced_notification_service_unit_test.cpp", + "distributed_device_status_test.cpp", "mock/mock_accesstoken_kit.cpp", "mock/mock_bundle_mgr.cpp", "mock/mock_datashare.cpp", diff --git a/services/ans/test/unittest/advanced_notification_live_view_service_test.cpp b/services/ans/test/unittest/advanced_notification_live_view_service_test.cpp index 5e72d52fb..d4bb9f243 100644 --- a/services/ans/test/unittest/advanced_notification_live_view_service_test.cpp +++ b/services/ans/test/unittest/advanced_notification_live_view_service_test.cpp @@ -28,6 +28,7 @@ #include "notification_preferences.h" #include "notification_constant.h" #include "pixel_map.h" +#include "int_wrapper.h" using namespace testing::ext; using namespace OHOS::Security::AccessToken; @@ -360,5 +361,426 @@ HWTEST_F(AnsLiveViewServiceTest, AddToDelayNotificationList_001, Function | Smal advancedNotificationService_->AddToDelayNotificationList(record); ASSERT_EQ(advancedNotificationService_->delayNotificationList_.size(), 1); } + +/** + * @tc.name: OnSubscriberAdd_100 + * @tc.desc: Test OnSubscriberAdd when record is nullptr + * @tc.type: FUNC + */ +HWTEST_F(AnsLiveViewServiceTest, OnSubscriberAdd_100, Function | SmallTest | Level1) +{ + auto ret = advancedNotificationService_->OnSubscriberAdd(nullptr); + + ASSERT_EQ(ret, (int)ERR_ANS_INVALID_PARAM); +} + +/** + * @tc.name: OnSubscriberAdd_200 + * @tc.desc: Test OnSubscriberAdd when notification doesn't exist + * @tc.type: FUNC + */ +HWTEST_F(AnsLiveViewServiceTest, OnSubscriberAdd_200, Function | SmallTest | Level1) +{ + auto record = NotificationSubscriberManager::GetInstance()->CreateSubscriberRecord(nullptr); + + auto ret = advancedNotificationService_->OnSubscriberAdd(record); + + ASSERT_EQ(ret, (int)ERR_ANS_NOTIFICATION_NOT_EXISTS); +} + +/** + * @tc.name: OnSubscriberAdd_300 + * @tc.desc: Test OnSubscriberAdd when notification exists + * @tc.type: FUNC + */ +HWTEST_F(AnsLiveViewServiceTest, OnSubscriberAdd_300, Function | SmallTest | Level1) +{ + auto slotType = NotificationConstant::SlotType::LIVE_VIEW; + sptr request = new (std::nothrow) NotificationRequest(); + request->SetSlotType(slotType); + request->SetNotificationId(1); + auto liveContent = std::make_shared(); + auto content = std::make_shared(liveContent); + request->SetContent(content); + sptr bundle = new NotificationBundleOption("test", 1); + auto notificationRecord = advancedNotificationService_->MakeNotificationRecord(request, bundle); + advancedNotificationService_->AddToNotificationList(notificationRecord); + + auto record = NotificationSubscriberManager::GetInstance()->CreateSubscriberRecord(nullptr); + + auto ret = advancedNotificationService_->OnSubscriberAdd(record); + + ASSERT_EQ(ret, (int)ERR_OK); +} + +/** + * @tc.name: SetNotificationRequestToDb_100 + * @tc.desc: Test SetNotificationRequestToDb when isOnlyLocalUpdate is true + * @tc.type: FUNC + */ +HWTEST_F(AnsLiveViewServiceTest, SetNotificationRequestToDb_100, Function | SmallTest | Level1) +{ + auto slotType = NotificationConstant::SlotType::LIVE_VIEW; + sptr request = new (std::nothrow) NotificationRequest(); + request->SetSlotType(slotType); + request->SetNotificationId(1); + auto liveContent = std::make_shared(); + liveContent->SetIsOnlyLocalUpdate(true); + auto content = std::make_shared(liveContent); + request->SetContent(content); + sptr bundle = new NotificationBundleOption("test", 1); + AdvancedNotificationService::NotificationRequestDb requestDb = + { .request = request, .bundleOption = bundle}; + + auto ret = advancedNotificationService_->SetNotificationRequestToDb(requestDb); + + ASSERT_EQ(ret, (int)ERR_OK); +} + +/** + * @tc.name: UpdateInDelayNotificationList_100 + * @tc.desc: Test UpdateInDelayNotificationList when publish immediately + * @tc.type: FUNC + */ +HWTEST_F(AnsLiveViewServiceTest, UpdateInDelayNotificationList_100, Function | SmallTest | Level1) +{ + auto slotType = NotificationConstant::SlotType::LIVE_VIEW; + sptr request = new (std::nothrow) NotificationRequest(); + request->SetSlotType(slotType); + request->SetNotificationId(1); + request->SetPublishDelayTime(0); + auto liveContent = std::make_shared(); + auto content = std::make_shared(liveContent); + request->SetContent(content); + sptr bundle = new NotificationBundleOption("test", 1); + auto record = advancedNotificationService_->MakeNotificationRecord(request, bundle); + advancedNotificationService_->AddToDelayNotificationList(record); + + sptr request1 = new (std::nothrow) NotificationRequest(); + request1->SetSlotType(slotType); + request1->SetNotificationId(1); + request1->SetPublishDelayTime(1000); + auto liveContent1 = std::make_shared(); + auto content1 = std::make_shared(liveContent1); + request1->SetContent(content1); + sptr bundle1 = new NotificationBundleOption("test", 1); + auto record1 = advancedNotificationService_->MakeNotificationRecord(request1, bundle1); + advancedNotificationService_->UpdateInDelayNotificationList(record1); + + auto iter = advancedNotificationService_->delayNotificationList_.begin(); + ASSERT_EQ((*iter).first->request->GetPublishDelayTime(), 1000); +} + +/** + * @tc.name: SaPublishSystemLiveViewAsBundle_100 + * @tc.desc: Test SaPublishSystemLiveViewAsBundle when publish immediately + * @tc.type: FUNC + */ +HWTEST_F(AnsLiveViewServiceTest, SaPublishSystemLiveViewAsBundle_100, Function | SmallTest | Level1) +{ + auto slotType = NotificationConstant::SlotType::LIVE_VIEW; + sptr request = new (std::nothrow) NotificationRequest(); + request->SetSlotType(slotType); + request->SetNotificationId(1); + request->SetPublishDelayTime(0); + auto liveContent = std::make_shared(); + auto content = std::make_shared(liveContent); + request->SetContent(content); + sptr bundle = new NotificationBundleOption("test", 1); + auto record = advancedNotificationService_->MakeNotificationRecord(request, bundle); + + auto ret = advancedNotificationService_->SaPublishSystemLiveViewAsBundle(record); + + ASSERT_EQ(ret, (int)ERR_OK); +} + +/** + * @tc.name: SaPublishSystemLiveViewAsBundle_200 + * @tc.desc: Test SaPublishSystemLiveViewAsBundle when notification exists + * @tc.type: FUNC + */ +HWTEST_F(AnsLiveViewServiceTest, SaPublishSystemLiveViewAsBundle_200, Function | SmallTest | Level1) +{ + auto slotType = NotificationConstant::SlotType::LIVE_VIEW; + sptr request = new (std::nothrow) NotificationRequest(); + request->SetSlotType(slotType); + request->SetNotificationId(1); + request->SetPublishDelayTime(1000); + auto liveContent = std::make_shared(); + auto content = std::make_shared(liveContent); + request->SetContent(content); + sptr bundle = new NotificationBundleOption("test", 1); + auto record = advancedNotificationService_->MakeNotificationRecord(request, bundle); + advancedNotificationService_->AddToDelayNotificationList(record); + + auto ret = advancedNotificationService_->SaPublishSystemLiveViewAsBundle(record); + + ASSERT_EQ(ret, (int)ERR_OK); +} + +/** + * @tc.name: SaPublishSystemLiveViewAsBundle_300 + * @tc.desc: Test SaPublishSystemLiveViewAsBundle when notification doesn't exist + * @tc.type: FUNC + */ +HWTEST_F(AnsLiveViewServiceTest, SaPublishSystemLiveViewAsBundle_300, Function | SmallTest | Level1) +{ + auto slotType = NotificationConstant::SlotType::LIVE_VIEW; + sptr request = new (std::nothrow) NotificationRequest(); + request->SetSlotType(slotType); + request->SetNotificationId(1); + request->SetPublishDelayTime(1000); + auto liveContent = std::make_shared(); + auto content = std::make_shared(liveContent); + request->SetContent(content); + sptr bundle = new NotificationBundleOption("test", 1); + auto record = advancedNotificationService_->MakeNotificationRecord(request, bundle); + + auto ret = advancedNotificationService_->SaPublishSystemLiveViewAsBundle(record); + + ASSERT_EQ(ret, (int)ERR_OK); +} + +/** + * @tc.name: IsNotificationExistsInDelayList_100 + * @tc.desc: Test IsNotificationExistsInDelayList when notification exists + * @tc.type: FUNC + */ +HWTEST_F(AnsLiveViewServiceTest, IsNotificationExistsInDelayList_100, Function | SmallTest | Level1) +{ + auto slotType = NotificationConstant::SlotType::LIVE_VIEW; + sptr request = new (std::nothrow) NotificationRequest(); + request->SetSlotType(slotType); + request->SetNotificationId(1); + auto liveContent = std::make_shared(); + auto content = std::make_shared(liveContent); + request->SetContent(content); + sptr bundle = new NotificationBundleOption("test", 1); + auto record = advancedNotificationService_->MakeNotificationRecord(request, bundle); + advancedNotificationService_->AddToDelayNotificationList(record); + std::string key = record->notification->GetKey(); + + auto ret = advancedNotificationService_->IsNotificationExistsInDelayList(key); + + ASSERT_TRUE(ret); +} + +/** + * @tc.name: IsNotificationExistsInDelayList_200 + * @tc.desc: Test IsNotificationExistsInDelayList when notification doesn't exist + * @tc.type: FUNC + */ +HWTEST_F(AnsLiveViewServiceTest, IsNotificationExistsInDelayList_200, Function | SmallTest | Level1) +{ + std::string key = "bunlde"; + + auto ret = advancedNotificationService_->IsNotificationExistsInDelayList(key); + + ASSERT_FALSE(ret); +} + +/** + * @tc.name: StartPublishDelayedNotificationTimeOut_100 + * @tc.desc: Test StartPublishDelayedNotificationTimeOut when publish with updateOnly is true + * @tc.type: FUNC + */ +HWTEST_F(AnsLiveViewServiceTest, StartPublishDelayedNotificationTimeOut_100, Function | SmallTest | Level1) +{ + int32_t ownerUid = 1; + int32_t notificationId = 1; + + advancedNotificationService_->StartPublishDelayedNotificationTimeOut(ownerUid, notificationId); + + auto ret = advancedNotificationService_->GetFromDelayedNotificationList(ownerUid, notificationId); + ASSERT_EQ(ret, nullptr); +} + +/** + * @tc.name: StartPublishDelayedNotification_100 + * @tc.desc: Test StartPublishDelayedNotification when publish with updateOnly is true + * @tc.type: FUNC + */ +HWTEST_F(AnsLiveViewServiceTest, StartPublishDelayedNotification_100, Function | SmallTest | Level1) +{ + auto slotType = NotificationConstant::SlotType::LIVE_VIEW; + sptr request = new (std::nothrow) NotificationRequest(); + request->SetSlotType(slotType); + request->SetUpdateOnly(true); + request->SetNotificationId(1); + auto liveContent = std::make_shared(); + auto content = std::make_shared(liveContent); + request->SetContent(content); + sptr bundle = new NotificationBundleOption("test", 1); + auto record = advancedNotificationService_->MakeNotificationRecord(request, bundle); + + auto ret = advancedNotificationService_->StartPublishDelayedNotification(record); + + ASSERT_EQ(ret, (int)ERR_ANS_NOTIFICATION_NOT_EXISTS); +} + +/** + * @tc.name: StartPublishDelayedNotification_200 + * @tc.desc: Test StartPublishDelayedNotification when notificationList_ is empty + * @tc.type: FUNC + */ +HWTEST_F(AnsLiveViewServiceTest, StartPublishDelayedNotification_200, Function | SmallTest | Level1) +{ + auto slotType = NotificationConstant::SlotType::LIVE_VIEW; + sptr request = new (std::nothrow) NotificationRequest(); + request->SetSlotType(slotType); + request->SetNotificationId(1); + request->SetAutoDeletedTime(INT64_MAX); + auto liveContent = std::make_shared(); + auto content = std::make_shared(liveContent); + request->SetContent(content); + sptr bundle = new NotificationBundleOption("test", 1); + auto record = advancedNotificationService_->MakeNotificationRecord(request, bundle); + + auto ret = advancedNotificationService_->StartPublishDelayedNotification(record); + + ASSERT_EQ(ret, (int)ERR_OK); +} + +/** + * @tc.name: UpdateRecordByOwner_100 + * @tc.desc: Test UpdateRecordByOwner when notificationList_ is empty + * @tc.type: FUNC + */ +HWTEST_F(AnsLiveViewServiceTest, UpdateRecordByOwner_100, Function | SmallTest | Level1) +{ + auto slotType = NotificationConstant::SlotType::LIVE_VIEW; + sptr request = new (std::nothrow) NotificationRequest(); + request->SetSlotType(slotType); + request->SetNotificationId(1); + auto liveContent = std::make_shared(); + auto content = std::make_shared(liveContent); + request->SetContent(content); + sptr bundle = new NotificationBundleOption("test", 1); + auto record = advancedNotificationService_->MakeNotificationRecord(request, bundle); + bool isSystem = false; + + advancedNotificationService_->UpdateRecordByOwner(record, isSystem); + auto creatorUid = request->GetCreatorUid(); + auto notificationId = request->GetNotificationId(); + auto ret = advancedNotificationService_->GetFromNotificationList(creatorUid, notificationId); + + ASSERT_EQ(ret, nullptr); +} + +/** + * @tc.name: UpdateRecordByOwner_200 + * @tc.desc: Test UpdateRecordByOwner when isSystem is true and timerId is 0 + * @tc.type: FUNC + */ +HWTEST_F(AnsLiveViewServiceTest, UpdateRecordByOwner_200, Function | SmallTest | Level1) +{ + auto slotType = NotificationConstant::SlotType::LIVE_VIEW; + sptr request = new (std::nothrow) NotificationRequest(); + request->SetSlotType(slotType); + request->SetNotificationId(1); + auto localLiveViewContent = std::make_shared(); + auto content = std::make_shared(localLiveViewContent); + request->SetContent(content); + request->SetUpdateByOwnerAllowed(true); + std::shared_ptr notiTemplate = std::make_shared(); + std::shared_ptr data = std::make_shared(); + data->SetParam("progressValue", AAFwk::Integer::Box(1)); + notiTemplate->SetTemplateData(data); + request->SetTemplate(notiTemplate); + std::shared_ptr agent = + std::make_shared(); + request->SetWantAgent(agent); + sptr bundle = new NotificationBundleOption("test", 1); + auto record = advancedNotificationService_->MakeNotificationRecord(request, bundle); + record->notification->SetFinishTimer(1); + advancedNotificationService_->AddToNotificationList(record); + bool isSystem = true; + + advancedNotificationService_->UpdateRecordByOwner(record, isSystem); + auto ret = record->notification->GetFinishTimer(); + + ASSERT_EQ(ret, 0); +} + +/** + * @tc.name: UpdateRecordByOwner_300 + * @tc.desc: Test UpdateRecordByOwner when isSystem is false and timerId is not 0 + * @tc.type: FUNC + */ +HWTEST_F(AnsLiveViewServiceTest, UpdateRecordByOwner_300, Function | SmallTest | Level1) +{ + auto slotType = NotificationConstant::SlotType::LIVE_VIEW; + sptr request = new (std::nothrow) NotificationRequest(); + request->SetSlotType(slotType); + request->SetNotificationId(1); + auto localLiveViewContent = std::make_shared(); + auto content = std::make_shared(localLiveViewContent); + request->SetContent(content); + request->SetUpdateByOwnerAllowed(true); + std::shared_ptr notiTemplate = std::make_shared(); + std::shared_ptr data = std::make_shared(); + data->SetParam("progressValue", AAFwk::Integer::Box(1)); + notiTemplate->SetTemplateData(data); + request->SetTemplate(notiTemplate); + std::shared_ptr agent = + std::make_shared(); + request->SetWantAgent(agent); + sptr bundle = new NotificationBundleOption("test", 1); + auto record = advancedNotificationService_->MakeNotificationRecord(request, bundle); + record->notification->SetFinishTimer(1); + advancedNotificationService_->AddToNotificationList(record); + bool isSystem = false; + + advancedNotificationService_->UpdateRecordByOwner(record, isSystem); + auto ret = record->notification->GetFinishTimer(); + + ASSERT_NE(ret, 0); +} + +/** + * @tc.name: StartFinishTimerForUpdate_100 + * @tc.desc: Test StartFinishTimerForUpdate when process is FINISH_PER + * @tc.type: FUNC + */ +HWTEST_F(AnsLiveViewServiceTest, StartFinishTimerForUpdate_100, Function | SmallTest | Level1) +{ + auto slotType = NotificationConstant::SlotType::LIVE_VIEW; + sptr request = new (std::nothrow) NotificationRequest(); + request->SetSlotType(slotType); + request->SetNotificationId(1); + auto liveContent = std::make_shared(); + auto content = std::make_shared(liveContent); + request->SetContent(content); + sptr bundle = new NotificationBundleOption("test", 1); + auto record = advancedNotificationService_->MakeNotificationRecord(request, bundle); + uint64_t process = NotificationConstant::FINISH_PER; + + advancedNotificationService_->StartFinishTimerForUpdate(record, process); + + ASSERT_EQ(record->finish_status, AdvancedNotificationService::UploadStatus::FINISH); +} + +/** + * @tc.name: StartFinishTimerForUpdate_200 + * @tc.desc: Test StartFinishTimerForUpdate when process is not FINISH_PER + * @tc.type: FUNC + */ +HWTEST_F(AnsLiveViewServiceTest, StartFinishTimerForUpdate_200, Function | SmallTest | Level1) +{ + auto slotType = NotificationConstant::SlotType::LIVE_VIEW; + sptr request = new (std::nothrow) NotificationRequest(); + request->SetSlotType(slotType); + request->SetNotificationId(1); + auto liveContent = std::make_shared(); + auto content = std::make_shared(liveContent); + request->SetContent(content); + sptr bundle = new NotificationBundleOption("test", 1); + auto record = advancedNotificationService_->MakeNotificationRecord(request, bundle); + uint64_t process = NotificationConstant::DEFAULT_FINISH_STATUS; + + advancedNotificationService_->StartFinishTimerForUpdate(record, process); + + ASSERT_EQ(record->finish_status, AdvancedNotificationService::UploadStatus::CONTINUOUS_UPDATE_TIME_OUT); +} } // namespace Notification } // namespace OHOS diff --git a/services/ans/test/unittest/distributed_device_status_test.cpp b/services/ans/test/unittest/distributed_device_status_test.cpp new file mode 100644 index 000000000..961f3863c --- /dev/null +++ b/services/ans/test/unittest/distributed_device_status_test.cpp @@ -0,0 +1,107 @@ +/* + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#define private public + +#include "distributed_device_status.h" + +using namespace testing::ext; +namespace OHOS { +namespace Notification { +class DistributedDeviceStatusTest : public testing::Test { +public: + static void SetUpTestCase() {}; + static void TearDownTestCase() {}; + void SetUp() {}; + void TearDown() {}; +}; + +/** + * @tc.name : SetDeviceStatus_100 + * @tc.desc : Test SetDeviceStatus function when deviceType is liteWearable and status is 0. + * @tc.type : FUNC + */ +HWTEST_F(DistributedDeviceStatusTest, SetDeviceStatus_100, Function | SmallTest | Level1) +{ + DistributedDeviceStatus distributedDeviceStatus; + std::string deviceType = "liteWearable"; + uint32_t status = 0; + uint32_t controlFlag = 1; + + ErrCode result = distributedDeviceStatus.SetDeviceStatus(deviceType, status, controlFlag); + + uint32_t value = 0; + ASSERT_TRUE(distributedDeviceStatus.deviceStatus_.Find("wearable", value)); +} + +/** + * @tc.name : SetDeviceStatus_200 + * @tc.desc : Test SetDeviceStatus function when deviceType is not liteWearable and status is 0. + * @tc.type : FUNC + */ +HWTEST_F(DistributedDeviceStatusTest, SetDeviceStatus_200, Function | SmallTest | Level1) +{ + DistributedDeviceStatus distributedDeviceStatus; + std::string deviceType = "not_liteWearable"; + uint32_t status = 0; + uint32_t controlFlag = 1; + + ErrCode result = distributedDeviceStatus.SetDeviceStatus(deviceType, status, controlFlag); + + uint32_t value = 0; + ASSERT_FALSE(distributedDeviceStatus.deviceStatus_.Find("wearable", value)); +} + +/** + * @tc.name : SetDeviceStatus_300 + * @tc.desc : Test SetDeviceStatus function when deviceType is liteWearable and status is not 0. + * @tc.type : FUNC + */ +HWTEST_F(DistributedDeviceStatusTest, SetDeviceStatus_300, Function | SmallTest | Level1) +{ + DistributedDeviceStatus distributedDeviceStatus; + std::string deviceType = "liteWearable"; + uint32_t status = 1; + uint32_t controlFlag = 1; + + ErrCode result = distributedDeviceStatus.SetDeviceStatus(deviceType, status, controlFlag); + + uint32_t value = 0; + ASSERT_TRUE(distributedDeviceStatus.deviceStatus_.Find("wearable", value)); + ASSERT_TRUE((distributedDeviceStatus.deviceStatus_.ReadVal("wearable") & status) != 0); +} + +/** + * @tc.name : SetDeviceStatus_400 + * @tc.desc : Test SetDeviceStatus function when deviceType is not liteWearable and status is not 0. + * @tc.type : FUNC + */ +HWTEST_F(DistributedDeviceStatusTest, SetDeviceStatus_400, Function | SmallTest | Level1) +{ + DistributedDeviceStatus distributedDeviceStatus; + std::string deviceType = "not_liteWearable"; + uint32_t status = 1; + uint32_t controlFlag = 1; + + ErrCode result = distributedDeviceStatus.SetDeviceStatus(deviceType, status, controlFlag); + + uint32_t value = 0; + ASSERT_FALSE(distributedDeviceStatus.deviceStatus_.Find("wearable", value)); + ASSERT_TRUE((distributedDeviceStatus.deviceStatus_.ReadVal(deviceType) & status) != 0); +} +} // Notification +} // OHOS \ No newline at end of file -- Gitee