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_do_not_disturb_date.h"
21 #undef private
22 #undef protected
23 
24 #include "notification_constant.h"
25 
26 using namespace testing::ext;
27 namespace OHOS {
28 namespace Notification {
29 class NotificationDoNotDisturbDateTest : public testing::Test {
30 public:
SetUpTestCase()31     static void SetUpTestCase() {}
TearDownTestCase()32     static void TearDownTestCase() {}
SetUp()33     void SetUp() {}
TearDown()34     void TearDown() {}
35 };
36 
37 /**
38  * @tc.name: SetDoNotDisturbType_00001
39  * @tc.desc: Test SetDoNotDisturbType parameters.
40  * @tc.type: FUNC
41  * @tc.require: issueI5WBBH
42  */
43 HWTEST_F(NotificationDoNotDisturbDateTest, SetDoNotDisturbType_00001, Function | SmallTest | Level1)
44 {
45     NotificationConstant::DoNotDisturbType doNotDisturbType = NotificationConstant::DoNotDisturbType::ONCE;
46     int64_t beginDate = 10;
47     int64_t endDate = 10;
48     auto rrc = std::make_shared<NotificationDoNotDisturbDate>(doNotDisturbType, beginDate, endDate);
49     rrc->SetDoNotDisturbType(doNotDisturbType);
50     EXPECT_EQ(rrc->GetDoNotDisturbType(), doNotDisturbType);
51 }
52 
53 /**
54  * @tc.name: SetBeginDate_00001
55  * @tc.desc: Test SetBeginDate parameters.
56  * @tc.type: FUNC
57  * @tc.require: issueI5WBBH
58  */
59 HWTEST_F(NotificationDoNotDisturbDateTest, SetBeginDate_00001, Function | SmallTest | Level1)
60 {
61     NotificationConstant::DoNotDisturbType doNotDisturbType = NotificationConstant::DoNotDisturbType::ONCE;
62     int64_t beginDate = 10;
63     int64_t beginDate1 = 20;
64     int64_t endDate = 10;
65     auto rrc = std::make_shared<NotificationDoNotDisturbDate>(doNotDisturbType, beginDate, endDate);
66     rrc->SetBeginDate(beginDate1);
67     EXPECT_EQ(rrc->GetBeginDate(), beginDate1);
68 }
69 
70 /**
71  * @tc.name: SetEndDate_00001
72  * @tc.desc: Test SetEndDate parameters.
73  * @tc.type: FUNC
74  * @tc.require: issueI5WBBH
75  */
76 HWTEST_F(NotificationDoNotDisturbDateTest, SetEndDate_00001, Function | SmallTest | Level1)
77 {
78     NotificationConstant::DoNotDisturbType doNotDisturbType = NotificationConstant::DoNotDisturbType::ONCE;
79     int64_t beginDate = 10;
80     int64_t endDate1 = 20;
81     int64_t endDate = 10;
82     auto rrc = std::make_shared<NotificationDoNotDisturbDate>(doNotDisturbType, beginDate, endDate);
83     rrc->SetEndDate(endDate1);
84     EXPECT_EQ(rrc->GetEndDate(), endDate1);
85 }
86 
87 /**
88  * @tc.name: Dump_00001
89  * @tc.desc: Test Dump parameters.
90  * @tc.type: FUNC
91  * @tc.require: issueI5WBBH
92  */
93 HWTEST_F(NotificationDoNotDisturbDateTest, Dump_00001, Function | SmallTest | Level1)
94 {
95     NotificationConstant::DoNotDisturbType doNotDisturbType = NotificationConstant::DoNotDisturbType::ONCE;
96     int64_t beginDate = 10;
97     int64_t endDate = 10;
98     auto rrc = std::make_shared<NotificationDoNotDisturbDate>(doNotDisturbType, beginDate, endDate);
99     std::string ret = "NotificationDoNotDisturbDate{ doNotDisturbType = 1, beginDate = 10, endDate = 10 }";
100     EXPECT_EQ(rrc->Dump(), ret);
101 }
102 
103 /**
104  * @tc.name: Marshalling_00001
105  * @tc.desc: Test Marshalling parameters.
106  * @tc.type: FUNC
107  * @tc.require: issueI5WBBH
108  */
109 HWTEST_F(NotificationDoNotDisturbDateTest, Marshalling_00001, Function | SmallTest | Level1)
110 {
111     Parcel parcel;
112     NotificationConstant::DoNotDisturbType doNotDisturbType = NotificationConstant::DoNotDisturbType::ONCE;
113     int64_t beginDate = 10;
114     int64_t endDate = 10;
115     auto rrc = std::make_shared<NotificationDoNotDisturbDate>(doNotDisturbType, beginDate, endDate);
116     EXPECT_EQ(rrc->Marshalling(parcel), true);
117 }
118 
119 /**
120  * @tc.name: Unmarshalling_00001
121  * @tc.desc: Test Unmarshalling parameters.
122  * @tc.type: FUNC
123  * @tc.require: issueI5WBBH
124  */
125 HWTEST_F(NotificationDoNotDisturbDateTest, Unmarshalling_001, Function | SmallTest | Level1)
126 {
127     bool unmarshalling = true;
128     Parcel parcel;
129     NotificationConstant::DoNotDisturbType doNotDisturbType = NotificationConstant::DoNotDisturbType::ONCE;
130     int64_t beginDate = 10;
131     int64_t endDate = 10;
132     std::shared_ptr<NotificationDoNotDisturbDate> result =
133     std::make_shared<NotificationDoNotDisturbDate>(doNotDisturbType, beginDate, endDate);
134     if (nullptr != result) {
135         if (nullptr == result->Unmarshalling(parcel)) {
136             unmarshalling = false;
137         }
138     }
139     EXPECT_EQ(unmarshalling, true);
140 }
141 
142 /**
143  * @tc.name: ReadFromParcel_00001
144  * @tc.desc: Test ReadFromParcel parameters.
145  * @tc.type: FUNC
146  * @tc.require: issueI5WBBH
147  */
148 HWTEST_F(NotificationDoNotDisturbDateTest, ReadFromParcel_00001, Function | SmallTest | Level1)
149 {
150     Parcel parcel;
151     NotificationConstant::DoNotDisturbType doNotDisturbType = NotificationConstant::DoNotDisturbType::ONCE;
152     int64_t beginDate = 10;
153     int64_t endDate = 10;
154     auto rrc = std::make_shared<NotificationDoNotDisturbDate>(doNotDisturbType, beginDate, endDate);
155     EXPECT_EQ(rrc->ReadFromParcel(parcel), true);
156 }
157 }
158 }