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_flags.h"
21 #undef private
22 #undef protected
23 
24 using namespace testing::ext;
25 namespace OHOS {
26 namespace Notification {
27 class NotificationFlagsTest : 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: SetSoundEnabled_00001
37  * @tc.desc: Test SetSoundEnabled parameters.
38  * @tc.type: FUNC
39  * @tc.require: issueI5WBBH
40  */
41 HWTEST_F(NotificationFlagsTest, SetSoundEnabled_00001, Function | SmallTest | Level1)
42 {
43     NotificationConstant::FlagStatus sound =NotificationConstant::FlagStatus(1);
44     auto rrc = std::make_shared<NotificationFlags>();
45     rrc->SetSoundEnabled(sound);
46     EXPECT_EQ(rrc->IsSoundEnabled(), sound);
47 }
48 
49 /**
50  * @tc.name: SetVibrationEnabled_00001
51  * @tc.desc: Test SetVibrationEnabled parameters.
52  * @tc.type: FUNC
53  * @tc.require: issueI5WBBH
54  */
55 HWTEST_F(NotificationFlagsTest, SetVibrationEnabled_00001, Function | SmallTest | Level1)
56 {
57     NotificationConstant::FlagStatus vibrationEnabled =NotificationConstant::FlagStatus(1);
58     auto rrc = std::make_shared<NotificationFlags>();
59     rrc->SetVibrationEnabled(vibrationEnabled);
60     EXPECT_EQ(rrc->IsVibrationEnabled(), vibrationEnabled);
61 }
62 
63 /**
64  * @tc.name: Dump_00001
65  * @tc.desc: Test Dump parameters.
66  * @tc.type: FUNC
67  * @tc.require: issueI5WBBH
68  */
69 HWTEST_F(NotificationFlagsTest, Dump_00001, Function | SmallTest | Level1)
70 {
71     auto rrc = std::make_shared<NotificationFlags>();
72     std::string ret = "soundEnabled = 0, vibrationEnabled = 0, reminderFlags = 0";
73     EXPECT_EQ(rrc->Dump(), ret);
74 }
75 
76 /**
77  * @tc.name: ToJson_00001
78  * @tc.desc: Test ToJson parameters.
79  * @tc.type: FUNC
80  * @tc.require: issueI5WBBH
81  */
82 HWTEST_F(NotificationFlagsTest, ToJson_00001, Function | SmallTest | Level1)
83 {
84     nlohmann::json jsonObject;
85     auto rrc = std::make_shared<NotificationFlags>();
86     rrc->FromJson(jsonObject);
87     EXPECT_EQ(rrc->ToJson(jsonObject), true);
88 }
89 
90 /**
91  * @tc.name: FromJson_00002
92  * @tc.desc: Test FromJson parameters.
93  * @tc.type: FUNC
94  * @tc.require: issue
95  */
96 HWTEST_F(NotificationFlagsTest, FromJson_00002, Function | SmallTest | Level1)
97 {
98     auto rrc = std::make_shared<NotificationFlags>();
99     nlohmann::json jsonObject = nlohmann::json{"processName", "soundEnabled", "name", "arrivedTime1"};
100     rrc->FromJson(jsonObject);
101     EXPECT_EQ(jsonObject.is_object(), false);
102     EXPECT_EQ(rrc->FromJson(jsonObject), nullptr);
103 }
104 
105 /**
106  * @tc.name: FromJson_00003
107  * @tc.desc: Test FromJson parameters.
108  * @tc.type: FUNC
109  * @tc.require: issue
110  */
111 HWTEST_F(NotificationFlagsTest, FromJson_00003, Function | SmallTest | Level1)
112 {
113     auto rrc = std::make_shared<NotificationFlags>();
114     nlohmann::json jsonObject = nlohmann::json{
115         {"processName", "process6"}, {"APL", 1},
116         {"version", 2}, {"tokenId", 685266937},
117         {"tokenAttr", 0},
118         {"dcaps", {"AT_CAP", "ST_CAP"}}};
119     rrc->FromJson(jsonObject);
120     EXPECT_EQ(jsonObject.is_object(), true);
121 }
122 
123 /**
124  * @tc.name: Marshalling_00001
125  * @tc.desc: Test Marshalling parameters.
126  * @tc.type: FUNC
127  * @tc.require: issueI5WBBH
128  */
129 HWTEST_F(NotificationFlagsTest, Marshalling_00001, Function | SmallTest | Level1)
130 {
131     Parcel parcel;
132     auto rrc = std::make_shared<NotificationFlags>();
133     EXPECT_EQ(rrc->Marshalling(parcel), true);
134 }
135 
136 /**
137  * @tc.name: Unmarshalling_00001
138  * @tc.desc: Test Unmarshalling parameters.
139  * @tc.type: FUNC
140  * @tc.require: issueI5WBBH
141  */
142 HWTEST_F(NotificationFlagsTest, Unmarshalling_001, Function | SmallTest | Level1)
143 {
144     bool unmarshalling = true;
145     Parcel parcel;
146     std::shared_ptr<NotificationFlags> result =
147     std::make_shared<NotificationFlags>();
148 
149     if (nullptr != result) {
150         if (nullptr == result->Unmarshalling(parcel)) {
151             unmarshalling = false;
152         }
153     }
154     EXPECT_EQ(unmarshalling, true);
155 }
156 
157 /**
158  * @tc.name: ReadFromParcel_00001
159  * @tc.desc: Test ReadFromParcel parameters.
160  * @tc.type: FUNC
161  * @tc.require: issueI5WBBH
162  */
163 HWTEST_F(NotificationFlagsTest, ReadFromParcel_00001, Function | SmallTest | Level1)
164 {
165     Parcel parcel;
166     auto rrc = std::make_shared<NotificationFlags>();
167     EXPECT_EQ(rrc->ReadFromParcel(parcel), true);
168 }
169 }
170 }