• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 #include "notification_clone_bundle_info.h"
18 #include "ans_inner_errors.h"
19 
20 using namespace testing::ext;
21 namespace OHOS {
22 namespace Notification {
23 constexpr const char *BUNDLE_INFO_NAME = "name";
24 constexpr const char *BUNDLE_INFO_APP_INDEX = "index";
25 constexpr const char *BUNDLE_INFO_SLOT_FLAGS = "slotFlags";
26 constexpr const char *BUNDLE_INFO_SHOW_BADGE = "badge";
27 constexpr const char *BUNDLE_INFO_ENABLE_NOTIFICATION = "enable";
28 constexpr const char *BUNDLE_INFO_SLOT_LIST = "slotList";
29 constexpr const char *BUNDLE_INFO_SLOT_TYPE = "slotType";
30 constexpr const char *BUNDLE_INFO_SLOT_ENABLE = "slotEnable";
31 constexpr const char *BUNDLE_INFO_SLOT_CONTROL = "slotControl";
32 class NotificationCloneBundleInfoTest : public testing::Test {
33 public:
SetUpTestCase()34     static void SetUpTestCase() {};
TearDownTestCase()35     static void TearDownTestCase() {};
SetUp()36     void SetUp() {};
TearDown()37     void TearDown() {};
38 };
39 
40 /**
41  * @tc.name: SetBundleName_00001
42  * @tc.desc: Test SetBundleName parameters.
43  * @tc.type: FUNC
44  * @tc.require: issue
45  */
46 HWTEST_F(NotificationCloneBundleInfoTest, SetBundleName_00001, Function | SmallTest | Level1)
47 {
48     std::string bundleName = "BundleName";
49     auto rrc = std::make_shared<NotificationCloneBundleInfo>();
50     rrc->SetBundleName(bundleName);
51     EXPECT_EQ(rrc->GetBundleName(), bundleName);
52 }
53 
54 /**
55  * @tc.name: SetAppIndex_00001
56  * @tc.desc: Test SetAppIndex parameters.
57  * @tc.type: FUNC
58  * @tc.require: issue
59  */
60 HWTEST_F(NotificationCloneBundleInfoTest, SetAppIndex_00001, Function | SmallTest | Level1)
61 {
62     int32_t appIndex = 1;
63     auto rrc = std::make_shared<NotificationCloneBundleInfo>();
64     rrc->SetAppIndex(appIndex);
65     EXPECT_EQ(rrc->GetAppIndex(), appIndex);
66 }
67 
68 /**
69  * @tc.name: SetUid_00001
70  * @tc.desc: Test SetUid parameters.
71  * @tc.type: FUNC
72  * @tc.require: issue
73  */
74 HWTEST_F(NotificationCloneBundleInfoTest, SetUid_00001, Function | SmallTest | Level1)
75 {
76     int32_t uid = 1;
77     auto rrc = std::make_shared<NotificationCloneBundleInfo>();
78     rrc->SetUid(uid);
79     EXPECT_EQ(rrc->GetUid(), uid);
80 }
81 
82 /**
83  * @tc.name: SetSlotFlags_00001
84  * @tc.desc: Test SetUid parameters.
85  * @tc.type: FUNC
86  * @tc.require: issue
87  */
88 HWTEST_F(NotificationCloneBundleInfoTest, SetSlotFlags_00001, Function | SmallTest | Level1)
89 {
90     int32_t slotFlags = 1;
91     auto rrc = std::make_shared<NotificationCloneBundleInfo>();
92     rrc->SetSlotFlags(slotFlags);
93     EXPECT_EQ(rrc->GetSlotFlags(), slotFlags);
94 }
95 
96 /**
97  * @tc.name: SetIsShowBadge_00001
98  * @tc.desc: Test SetIsShowBadge parameters.
99  * @tc.type: FUNC
100  * @tc.require: issue
101  */
102 HWTEST_F(NotificationCloneBundleInfoTest, SetIsShowBadge_00001, Function | SmallTest | Level1)
103 {
104     bool isShowBadge = true;
105     auto rrc = std::make_shared<NotificationCloneBundleInfo>();
106     rrc->SetIsShowBadge(isShowBadge);
107     EXPECT_EQ(rrc->GetIsShowBadge(), isShowBadge);
108 }
109 
110 /**
111  * @tc.name: SetEnableNotification_00001
112  * @tc.desc: Test SetEnableNotification parameters.
113  * @tc.type: FUNC
114  * @tc.require: issue
115  */
116 HWTEST_F(NotificationCloneBundleInfoTest, SetEnableNotification_00001, Function | SmallTest | Level1)
117 {
118     NotificationConstant::SWITCH_STATE enabledNotification = NotificationConstant::SWITCH_STATE::USER_MODIFIED_ON;
119     auto rrc = std::make_shared<NotificationCloneBundleInfo>();
120     rrc->SetEnableNotification(enabledNotification);
121     EXPECT_EQ(rrc->GetEnableNotification(), enabledNotification);
122 }
123 
124 /**
125  * @tc.name: AddSlotInfo_00001
126  * @tc.desc: Test AddSlotInfo parameters.
127  * @tc.type: FUNC
128  * @tc.require: issue
129  */
130 HWTEST_F(NotificationCloneBundleInfoTest, AddSlotInfo_00001, Function | SmallTest | Level1)
131 {
132     NotificationCloneBundleInfo::SlotInfo slotInfo;
133     slotInfo.slotType_ = NotificationConstant::SlotType::SOCIAL_COMMUNICATION;
134     slotInfo.enable_ = true;
135     slotInfo.isForceControl_ = true;
136     auto rrc = std::make_shared<NotificationCloneBundleInfo>();
137     rrc->AddSlotInfo(slotInfo);
138     EXPECT_EQ(rrc->GetSlotInfo().size(), 1);
139 }
140 
141 /**
142  * @tc.name: ToJson_00001
143  * @tc.desc: Test ToJson parameters.
144  * @tc.type: FUNC
145  * @tc.require: issue
146  */
147 HWTEST_F(NotificationCloneBundleInfoTest, ToJson_00001, Function | SmallTest | Level1)
148 {
149     std::string bundleName = "BundleName";
150     int32_t appIndex = 1;
151     int32_t uid = 1;
152     int32_t slotFlags = 1;
153     bool isShowBadge = true;
154     NotificationConstant::SWITCH_STATE enabledNotification = NotificationConstant::SWITCH_STATE::USER_MODIFIED_ON;
155     NotificationCloneBundleInfo::SlotInfo slotInfo;
156     slotInfo.slotType_ = NotificationConstant::SlotType::SOCIAL_COMMUNICATION;
157     slotInfo.enable_ = true;
158     slotInfo.isForceControl_ = true;
159     auto rrc = std::make_shared<NotificationCloneBundleInfo>();
160     rrc->SetBundleName(bundleName);
161     rrc->SetAppIndex(appIndex);
162     rrc->SetUid(uid);
163     rrc->SetSlotFlags(slotFlags);
164     rrc->SetIsShowBadge(isShowBadge);
165     rrc->SetEnableNotification(enabledNotification);
166     rrc->AddSlotInfo(slotInfo);
167     nlohmann::json jsonObject;
168     EXPECT_EQ(jsonObject.is_null(), true);
169     EXPECT_EQ(jsonObject.is_object(), false);
170     rrc->FromJson(jsonObject);
171     rrc->ToJson(jsonObject);
172     EXPECT_EQ(jsonObject.is_object(), true);
173     EXPECT_EQ(rrc->GetSlotInfo().size(), 1);
174     rrc->FromJson(jsonObject);
175     EXPECT_EQ(rrc->GetSlotInfo().size(), 2);
176 }
177 
178 /**
179  * @tc.name: Dump_00001
180  * @tc.desc: Test Dump parameters.
181  * @tc.type: FUNC
182  * @tc.require: issue
183  */
184 HWTEST_F(NotificationCloneBundleInfoTest, Dump_00001, Function | SmallTest | Level1)
185 {
186     std::string bundleName = "BundleName";
187     int32_t appIndex = 1;
188     int32_t uid = 1;
189     int32_t slotFlags = 1;
190     bool isShowBadge = true;
191     NotificationConstant::SWITCH_STATE enabledNotification = NotificationConstant::SWITCH_STATE::USER_MODIFIED_ON;
192     NotificationCloneBundleInfo::SlotInfo slotInfo;
193     slotInfo.slotType_ = NotificationConstant::SlotType::SOCIAL_COMMUNICATION;
194     slotInfo.enable_ = true;
195     slotInfo.isForceControl_ = true;
196     auto rrc = std::make_shared<NotificationCloneBundleInfo>();
197     rrc->SetBundleName(bundleName);
198     rrc->SetAppIndex(appIndex);
199     rrc->SetUid(uid);
200     rrc->SetSlotFlags(slotFlags);
201     rrc->SetIsShowBadge(isShowBadge);
202     rrc->SetEnableNotification(enabledNotification);
203     rrc->AddSlotInfo(slotInfo);
204     std::string dumpInfo;
205     EXPECT_EQ(dumpInfo.size(), 0);
206     std::string slotDump = "{";
207     for (auto& slot : rrc->GetSlotInfo()) {
208         slotDump += slot.Dump();
209         slotDump += ",";
210     }
211     slotDump += "}";
212     dumpInfo += "CloneBundle{ name = " + bundleName +
213             ", index = " + std::to_string(appIndex) +
214             ", uid = " + std::to_string(uid) +
215             ", slotFlags = " + std::to_string(slotFlags) +
216             ", ShowBadge = " + std::to_string(isShowBadge) +
217             ", isEnabled = " + std::to_string(static_cast<int32_t>(enabledNotification)) +
218             ", slotsInfo = " + slotDump +
219             ", silentReminderEnabled = 0" +
220             " }";
221     EXPECT_EQ(rrc->Dump(), dumpInfo);
222 }
223 }
224 }