• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "gtest/gtest.h"
17 
18 #define private public
19 
20 #include "ans_inner_errors.h"
21 #include "distributed_collaboration_service.h"
22 
23 namespace OHOS {
24 namespace Notification {
25 
26 using namespace testing::ext;
27 
28 class DistributedCollaborationServiceTest : public testing::Test {
29 public:
30     static void SetUpTestCase();
31     static void TearDownTestCase();
SetUp()32     void SetUp() {};
TearDown()33     void TearDown() {};
34 };
35 
SetUpTestCase()36 void DistributedCollaborationServiceTest::SetUpTestCase()
37 {
38 }
39 
TearDownTestCase()40 void DistributedCollaborationServiceTest::TearDownTestCase()
41 {
42 }
43 
44 /**
45  * @tc.name: Device sync switch check
46  * @tc.desc: Test device data service
47  * @tc.type: FUNC
48  * @tc.require: issue
49  */
50 HWTEST_F(DistributedCollaborationServiceTest, CollaborativeService_00001, Function | SmallTest | Level1)
51 {
52     DistributedCollaborationService::GetInstance().AddCollaborativeDeleteItem(nullptr);
53     ASSERT_EQ(DistributedCollaborationService::GetInstance().collaborativeDeleteMap_.empty(), true);
54 
55     sptr<Notification> notification1 = new (std::nothrow) Notification(nullptr);
56     notification1->SetKey("ans_distributed_1");
57     DistributedCollaborationService::GetInstance().AddCollaborativeDeleteItem(notification1);
58     ASSERT_EQ(DistributedCollaborationService::GetInstance().collaborativeDeleteMap_.empty(), true);
59 
60     sptr<NotificationRequest> request = new (std::nothrow) NotificationRequest();
61     request->SetNotificationId(1);
62     sptr<Notification> notification2 = new (std::nothrow) Notification(request);
63     notification2->SetKey("ans_distributed_2");
64     DistributedCollaborationService::GetInstance().AddCollaborativeDeleteItem(notification2);
65     ASSERT_EQ(DistributedCollaborationService::GetInstance().collaborativeDeleteMap_.empty(), true);
66 
67     request->SetDistributedCollaborate(true);
68     DistributedCollaborationService::GetInstance().AddCollaborativeDeleteItem(notification2);
69     ASSERT_EQ(DistributedCollaborationService::GetInstance().collaborativeDeleteMap_.empty(), true);
70 
71     auto liveviewContent = std::make_shared<NotificationLiveViewContent>();
72     auto content = std::make_shared<NotificationContent>(liveviewContent);
73     request->SetContent(content);
74     request->SetSlotType(NotificationConstant::SlotType::LIVE_VIEW);
75     DistributedCollaborationService::GetInstance().AddCollaborativeDeleteItem(notification2);
76     ASSERT_EQ(DistributedCollaborationService::GetInstance().collaborativeDeleteMap_.empty(), false);
77 }
78 
79 /**
80  * @tc.name: Device sync switch check
81  * @tc.desc: Test device data service
82  * @tc.type: FUNC
83  * @tc.require: issue
84  */
85 HWTEST_F(DistributedCollaborationServiceTest, CollaborativeService_00002, Function | SmallTest | Level1)
86 {
87     auto result = DistributedCollaborationService::GetInstance().CheckCollaborativePublish(nullptr);
88     ASSERT_EQ(result, true);
89 
90     sptr<Notification> notification1 = new (std::nothrow) Notification(nullptr);
91     notification1->SetKey("ans_distributed_1");
92     result = DistributedCollaborationService::GetInstance().CheckCollaborativePublish(notification1);
93     ASSERT_EQ(result, true);
94 
95     sptr<NotificationRequest> request = new (std::nothrow) NotificationRequest();
96     request->SetNotificationId(1);
97     sptr<Notification> notification2 = new (std::nothrow) Notification(request);
98     notification2->SetKey("ans_distributed_2");
99     result = DistributedCollaborationService::GetInstance().CheckCollaborativePublish(notification2);
100     ASSERT_EQ(result, true);
101 
102     request->SetDistributedCollaborate(true);
103     result = DistributedCollaborationService::GetInstance().CheckCollaborativePublish(notification2);
104     ASSERT_EQ(result, true);
105 
106     auto liveviewContent = std::make_shared<NotificationLiveViewContent>();
107     auto content = std::make_shared<NotificationContent>(liveviewContent);
108     request->SetContent(content);
109     request->SetSlotType(NotificationConstant::SlotType::LIVE_VIEW);
110     result = DistributedCollaborationService::GetInstance().CheckCollaborativePublish(notification2);
111     ASSERT_EQ(result, true);
112 }
113 
114 /**
115  * @tc.name: Collaborative Service
116  * @tc.desc: Test update after delete
117  * @tc.type: FUNC
118  * @tc.require: issue
119  */
120 HWTEST_F(DistributedCollaborationServiceTest, CollaborativeService_00003, Function | SmallTest | Level1)
121 {
122     DistributedCollaborationService::GetInstance().collaborativeDeleteMap_.clear();
123 
124     sptr<NotificationRequest> request = new (std::nothrow) NotificationRequest();
125     auto liveviewContent = std::make_shared<NotificationLiveViewContent>();
126     liveviewContent->SetLiveViewStatus(NotificationLiveViewContent::LiveViewStatus::LIVE_VIEW_CREATE);
127     auto content = std::make_shared<NotificationContent>(liveviewContent);
128     request->SetContent(content);
129     request->SetSlotType(NotificationConstant::SlotType::LIVE_VIEW);
130     request->SetDistributedCollaborate(true);
131     sptr<Notification> notification = new (std::nothrow) Notification(request);
132     notification->SetKey("ans_distributed_0003");
133     DistributedCollaborationService::GetInstance().AddCollaborativeDeleteItem(notification);
134 
135     auto result = DistributedCollaborationService::GetInstance().CheckCollaborativePublish(notification);
136     ASSERT_EQ(result, true);
137 
138     DistributedCollaborationService::GetInstance().AddCollaborativeDeleteItem(notification);
139     liveviewContent->SetLiveViewStatus(NotificationLiveViewContent::LiveViewStatus::LIVE_VIEW_INCREMENTAL_UPDATE);
140     result = DistributedCollaborationService::GetInstance().CheckCollaborativePublish(notification);
141     ASSERT_EQ(result, false);
142 }
143 }
144 }
145