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 "enabled_notification_callback_data.h"
21 #undef private
22 #undef protected
23 
24 using namespace testing::ext;
25 namespace OHOS {
26 namespace Notification {
27 class NotificationCallbackDataTest : 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: SetBundle_00001
37  * @tc.desc: Test SetBundle parameters.
38  * @tc.type: FUNC
39  * @tc.require: issueI5W15B
40  */
41 HWTEST_F(NotificationCallbackDataTest, SetBundle_00001, Function | SmallTest | Level1)
42 {
43     std::string bundle = "Bundle";
44     uid_t uid = 10;
45     bool enable = true;
46     auto rrc = std::make_shared<EnabledNotificationCallbackData>(bundle, uid, enable);
47     rrc->SetBundle(bundle);
48     EXPECT_EQ(rrc->GetBundle(), bundle);
49 }
50 
51 /**
52  * @tc.name: SetUid_00001
53  * @tc.desc: Test SetUid parameters.
54  * @tc.type: FUNC
55  * @tc.require: issueI5W15B
56  */
57 HWTEST_F(NotificationCallbackDataTest, SetUid_00001, Function | SmallTest | Level1)
58 {
59     std::string bundle = "Bundle";
60     uid_t uid = 10;
61     bool enable = true;
62     auto rrc = std::make_shared<EnabledNotificationCallbackData>(bundle, uid, enable);
63     rrc->SetUid(uid);
64     EXPECT_EQ(rrc->GetUid(), uid);
65 }
66 
67 /**
68  * @tc.name: SetEnable_00001
69  * @tc.desc: Test SetEnable parameters.
70  * @tc.type: FUNC
71  * @tc.require: issueI5W15B
72  */
73 HWTEST_F(NotificationCallbackDataTest, SetEnable_00001, Function | SmallTest | Level1)
74 {
75     std::string bundle = "Bundle";
76     uid_t uid = 10;
77     bool enable = true;
78     auto rrc = std::make_shared<EnabledNotificationCallbackData>(bundle, uid, enable);
79     rrc->SetEnable(enable);
80     EXPECT_EQ(rrc->GetEnable(), enable);
81 }
82 
83 /**
84  * @tc.name: Dump_00001
85  * @tc.desc: Test Dump parameters.
86  * @tc.type: FUNC
87  * @tc.require: issueI5W15B
88  */
89 HWTEST_F(NotificationCallbackDataTest, Dump_00001, Function | SmallTest | Level1)
90 {
91     std::string bundle = "Bundle";
92     uid_t uid = 10;
93     bool enable = true;
94     std::string result = "EnabledNotificationCallbackData{ bundle = Bundle, uid = 10, enable = 1 }";
95     auto rrc = std::make_shared<EnabledNotificationCallbackData>(bundle, uid, enable);
96     EXPECT_EQ(rrc->Dump(), result);
97 }
98 
99 /**
100  * @tc.name: Marshalling_00001
101  * @tc.desc: Test Marshalling parameters.
102  * @tc.type: FUNC
103  * @tc.require: issueI5W15B
104  */
105 HWTEST_F(NotificationCallbackDataTest, Marshalling_00001, Function | SmallTest | Level1)
106 {
107     std::string bundle = "Bundle";
108     uid_t uid = 10;
109     bool enable = true;
110     Parcel parcel;
111     auto rrc = std::make_shared<EnabledNotificationCallbackData>(bundle, uid, enable);
112     EXPECT_EQ(rrc->Marshalling(parcel), true);
113 }
114 
115 /**
116  * @tc.name: Unmarshalling_00001
117  * @tc.desc: Test Unmarshalling parameters.
118  * @tc.type: FUNC
119  * @tc.require: issueI5W15B
120  */
121 HWTEST_F(NotificationCallbackDataTest, Unmarshalling_00001, Function | SmallTest | Level1)
122 {
123     std::string bundle = "Bundle";
124     uid_t uid = 10;
125     bool enable = true;
126     bool unmarshalling = true;
127     Parcel parcel;
128     auto rrc = std::make_shared<EnabledNotificationCallbackData>(bundle, uid, enable);
129     if (nullptr != rrc) {
130         if (nullptr == rrc->Unmarshalling(parcel)) {
131             unmarshalling = false;
132         }
133     }
134     EXPECT_EQ(unmarshalling, true);
135 }
136 
137 /**
138  * @tc.name: ReadFromParcel_00001
139  * @tc.desc: Test ReadFromParcel parameters.
140  * @tc.type: FUNC
141  * @tc.require: issueI5W15B
142  */
143 HWTEST_F(NotificationCallbackDataTest, ReadFromParcel_00001, Function | SmallTest | Level1)
144 {
145     std::string bundle = "Bundle";
146     uid_t uid = 10;
147     bool enable = true;
148     Parcel parcel;
149     auto rrc = std::make_shared<EnabledNotificationCallbackData>(bundle, uid, enable);
150     EXPECT_EQ(rrc->ReadFromParcel(parcel), true);
151 }
152 }
153 }