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 NotificationSortingTest : 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: Marshalling_00001
37  * @tc.desc: Test Marshalling parameters.
38  * @tc.type: FUNC
39  * @tc.require: issue
40  */
41 HWTEST_F(NotificationSortingTest, Marshalling_00001, Function | SmallTest | Level1)
42 {
43     NotificationSorting sorting;
44     Parcel parcel;
45     auto rrc = std::make_shared<NotificationSorting>(sorting);
46     EXPECT_EQ(rrc->Marshalling(parcel), true);
47 }
48 
49 /**
50  * @tc.name: Marshalling_00002
51  * @tc.desc: Test Marshalling parameters.
52  * @tc.type: FUNC
53  * @tc.require: issue
54  */
55 HWTEST_F(NotificationSortingTest, Marshalling_00002, Function | SmallTest | Level1)
56 {
57     NotificationSorting sorting;
58     Parcel parcel;
59     auto rrc = std::make_shared<NotificationSorting>(sorting);
60     rrc->SetKey("");
61     rrc->ReadFromParcel(parcel);
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(NotificationSortingTest, Unmarshalling_001, Function | SmallTest | Level1)
72 {
73     NotificationSorting sorting;
74     sptr<NotificationSlot> slot = new (std::nothrow) NotificationSlot();
75     sorting.SetSlot(slot);
76     bool unmarshalling = true;
77     Parcel parcel;
78     std::shared_ptr<NotificationSorting> result =
79     std::make_shared<NotificationSorting>(sorting);
80     result->Marshalling(parcel);
81     if (nullptr != result) {
82         if (nullptr == result->Unmarshalling(parcel)) {
83             unmarshalling = false;
84         }
85     }
86     EXPECT_EQ(unmarshalling, true);
87 }
88 
89 /**
90  * @tc.name: ReadFromParcel_00001
91  * @tc.desc: Test ReadFromParcel parameters.
92  * @tc.type: FUNC
93  * @tc.require: issueI5WBBH
94  */
95 HWTEST_F(NotificationSortingTest, ReadFromParcel_00001, Function | SmallTest | Level1)
96 {
97     Parcel parcel;
98     NotificationSorting sorting;
99     sptr<NotificationSlot> slot = new (std::nothrow) NotificationSlot();
100     sorting.SetSlot(slot);
101     auto rrc = std::make_shared<NotificationSorting>(sorting);
102     rrc->Marshalling(parcel);
103     EXPECT_EQ(rrc->ReadFromParcel(parcel), true);
104 }
105 
106 /**
107  * @tc.name: Dump_00001
108  * @tc.desc: Test Dump parameters.
109  * @tc.type: FUNC
110  * @tc.require: issue
111  */
112 HWTEST_F(NotificationSortingTest, Dump_00001, Function | SmallTest | Level1)
113 {
114     NotificationSorting sorting;
115     Parcel parcel;
116     std::string groupKeyOverride = "GroupKeyOverride";
117     std::string key = "Key";
118     int32_t importance = 10;
119     uint64_t ranking = 20;
120     int32_t visibleness =30;
121     bool isDisplayBadge = false;
122     bool isHiddenNotification = true;
123     auto rrc = std::make_shared<NotificationSorting>(sorting);
124     rrc->SetGroupKeyOverride(groupKeyOverride);
125     rrc->SetKey(key);
126     rrc->SetImportance(importance);
127     rrc->SetRanking(ranking);
128     rrc->SetVisiblenessOverride(visibleness);
129     rrc->SetDisplayBadge(isDisplayBadge);
130     rrc->SetHiddenNotification(isHiddenNotification);
131     std::string ret = "NotificationSorting{ key = Key, ranking = 20, importance = 10, "
132     "visiblenessOverride = 30, isDisplayBadge = false, isHiddenNotification = true, "
133     "groupKeyOverride = GroupKeyOverride, slot = NotificationSlot{ id = OTHER, name "
134     "= OTHER, description = , type = 3, level = 1, isBypassDnd = false, visibleness = "
135     "3, sound = , isLightEnabled = false, lightColor = 0, isVibrate = false, vibration "
136     "= , isShowBadge = true, enabled = true, slotFlags = 0, remindMode = 0 } }";
137     EXPECT_EQ(rrc->Dump(), ret);
138 }
139 }
140 }
141