1 /* 2 * Copyright (c) 2022 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 #define protected public 20 #include "notification_sorting_map.h" 21 #undef private 22 #undef protected 23 24 using namespace testing::ext; 25 namespace OHOS { 26 namespace Notification { 27 class NotificationSortingMapTest : public testing::Test { 28 public: SetUpTestCase()29 static void SetUpTestCase() {} TearDownTestCase()30 static void TearDownTestCase() {} SetUp()31 void SetUp() {} TearDown()32 void TearDown() {} 33 }; 34 35 /** 36 * @tc.name: SetKey_00001 37 * @tc.desc: Test SetKey parameters. 38 * @tc.type: FUNC 39 * @tc.require: issue 40 */ 41 HWTEST_F(NotificationSortingMapTest, SetKey_00001, Function | SmallTest | Level1) 42 { 43 std::vector<NotificationSorting> sortingList; 44 std::string key = "Key"; 45 auto rrc = std::make_shared<NotificationSortingMap>(sortingList); 46 NotificationSorting sorting; 47 rrc->SetNotificationSorting(sortingList); 48 EXPECT_EQ(rrc->GetNotificationSorting(key, sorting), false); 49 } 50 51 /** 52 * @tc.name: Marshalling_00001 53 * @tc.desc: Test Marshalling parameters. 54 * @tc.type: FUNC 55 * @tc.require: issue 56 */ 57 HWTEST_F(NotificationSortingMapTest, Marshalling_00001, Function | SmallTest | Level1) 58 { 59 std::vector<NotificationSorting> sortingList; 60 Parcel parcel; 61 auto rrc = std::make_shared<NotificationSortingMap>(sortingList); 62 EXPECT_EQ(rrc->Marshalling(parcel), true); 63 } 64 65 /** 66 * @tc.name: Unmarshalling_00001 67 * @tc.desc: Test Unmarshalling parameters. 68 * @tc.type: FUNC 69 * @tc.require: issue 70 */ 71 HWTEST_F(NotificationSortingMapTest, Unmarshalling_001, Function | SmallTest | Level1) 72 { 73 std::vector<NotificationSorting> sortingList; 74 bool unmarshalling = true; 75 Parcel parcel; 76 std::shared_ptr<NotificationSortingMap> result = 77 std::make_shared<NotificationSortingMap>(sortingList); 78 79 if (nullptr != result) { 80 if (nullptr == result->Unmarshalling(parcel)) { 81 unmarshalling = false; 82 } 83 } 84 EXPECT_EQ(unmarshalling, true); 85 } 86 87 /** 88 * @tc.name: Unmarshalling_00002 89 * @tc.desc: Test Unmarshalling parameters. 90 * @tc.type: FUNC 91 * @tc.require: issue 92 */ 93 HWTEST_F(NotificationSortingMapTest, Unmarshalling_00002, Function | SmallTest | Level1) 94 { 95 std::string groupKeyOverride = "GroupKeyOverride"; 96 int32_t importance = 10; 97 uint64_t ranking = 20; 98 int32_t visibleness =30; 99 bool isDisplayBadge = false; 100 bool isHiddenNotification = true; 101 NotificationSorting sorting; 102 sorting.SetGroupKeyOverride(groupKeyOverride); 103 sorting.SetImportance(importance); 104 sorting.SetRanking(ranking); 105 sorting.SetVisiblenessOverride(visibleness); 106 sorting.SetDisplayBadge(isDisplayBadge); 107 sorting.SetHiddenNotification(isHiddenNotification); 108 109 std::vector<NotificationSorting> sortingList; 110 for (size_t i = 0; i <= MAX_ACTIVE_NUM + 1; i++) { 111 sorting.SetKey(std::to_string(i)); 112 sortingList.emplace_back(sorting); 113 } 114 115 auto sortingMap = std::make_shared<NotificationSortingMap>(sortingList); 116 NotificationSorting sortingTmp; 117 Parcel parcel; 118 EXPECT_EQ(sortingMap->Marshalling(parcel), true); 119 auto newSortingMap = sortingMap->Unmarshalling(parcel); 120 EXPECT_NE(newSortingMap, nullptr); 121 EXPECT_EQ(newSortingMap->GetNotificationSorting(std::to_string(MAX_ACTIVE_NUM), sortingTmp), true); 122 } 123 124 /** 125 * @tc.name: Dump_00001 126 * @tc.desc: Test Dump parameters. 127 * @tc.type: FUNC 128 * @tc.require: issue 129 */ 130 HWTEST_F(NotificationSortingMapTest, Dump_00001, Function | SmallTest | Level1) 131 { 132 std::vector<NotificationSorting> sortingList; 133 std::string key = "Key"; 134 auto rrc = std::make_shared<NotificationSortingMap>(sortingList); 135 rrc->SetKey(key); 136 std::string ret = "NotificationSortingMap{ sortedkey = [Key, ] }"; 137 EXPECT_EQ(rrc->Dump(), ret); 138 } 139 140 /** 141 * @tc.name: SetKey_00002 142 * @tc.desc: Test SetKey parameters. 143 * @tc.type: FUNC 144 * @tc.require: issue 145 */ 146 HWTEST_F(NotificationSortingMapTest, SetKey_00002, Function | SmallTest | Level1) 147 { 148 std::vector<NotificationSorting> sortingList; 149 std::string key = ""; 150 151 auto rrc = std::make_shared<NotificationSortingMap>(sortingList); 152 EXPECT_NE(rrc, nullptr); 153 rrc->SetKey(key); 154 } 155 156 /** 157 * @tc.name: SetKey_00003 158 * @tc.desc: Test SetKey parameters. 159 * @tc.type: FUNC 160 * @tc.require: issue 161 */ 162 HWTEST_F(NotificationSortingMapTest, SetKey_00003, Function | SmallTest | Level1) 163 { 164 std::vector<NotificationSorting> sortingList; 165 std::string key = "Key"; 166 auto rrc = std::make_shared<NotificationSortingMap>(sortingList); 167 NotificationSorting sorting; 168 sortingList.emplace_back(sorting); 169 rrc->SetNotificationSorting(sortingList); 170 EXPECT_EQ(rrc->GetNotificationSorting(key, sorting), false); 171 } 172 173 /** 174 * @tc.name: SetKey_00004 175 * @tc.desc: Test SetKey parameters. 176 * @tc.type: FUNC 177 * @tc.require: issue 178 */ 179 HWTEST_F(NotificationSortingMapTest, SetKey_00004, Function | SmallTest | Level1) 180 { 181 std::vector<NotificationSorting> sortingList; 182 std::string key = "Key"; 183 auto rrc = std::make_shared<NotificationSortingMap>(sortingList); 184 NotificationSorting sorting; 185 sortingList.emplace_back(sorting); 186 rrc->SetNotificationSorting(sortingList); 187 EXPECT_EQ(rrc->GetNotificationSorting("test", sorting), false); 188 } 189 } 190 } 191