1 /* 2 * Copyright (c) 2023 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 #include <string> 18 #include <unistd.h> 19 #include "notification_time.h" 20 21 using namespace testing::ext; 22 namespace OHOS { 23 namespace Notification { 24 class NotificationTimeTest : public testing::Test { 25 public: SetUpTestCase()26 static void SetUpTestCase() {} TearDownTestCase()27 static void TearDownTestCase() {} SetUp()28 void SetUp() {} TearDown()29 void TearDown() {} 30 }; 31 32 /** 33 * @tc.name: SetInitialTime_00001 34 * @tc.desc: Test initialTime_ parameters. 35 * @tc.type: FUNC 36 * @tc.require: issue 37 */ 38 HWTEST_F(NotificationTimeTest, SetInitialTime_00001, Function | SmallTest | Level1) 39 { 40 auto rrc = std::make_shared<NotificationTime>(); 41 int32_t initialTime = 1; 42 rrc->SetInitialTime(initialTime); 43 EXPECT_EQ(rrc->GetInitialTime(), initialTime); 44 } 45 46 /** 47 * @tc.name: SetIsCountDown_00001 48 * @tc.desc: Test isCountDown_ parameters. 49 * @tc.type: FUNC 50 * @tc.require: issue 51 */ 52 HWTEST_F(NotificationTimeTest, SetIsCountDown_00001, Function | SmallTest | Level1) 53 { 54 auto rrc = std::make_shared<NotificationTime>(); 55 bool isCountDown = true; 56 rrc->SetIsCountDown(isCountDown); 57 EXPECT_EQ(rrc->GetIsCountDown(), isCountDown); 58 } 59 60 /** 61 * @tc.name: SetIsPaused_0001 62 * @tc.desc: Test isPaused_ parameters. 63 * @tc.type: FUNC 64 * @tc.require: issue 65 */ 66 HWTEST_F(NotificationTimeTest, SetIsPaused_0001, Function | SmallTest | Level1) 67 { 68 auto rrc = std::make_shared<NotificationTime>(); 69 bool isPaused = true; 70 rrc->SetIsPaused(isPaused); 71 EXPECT_EQ(rrc->GetIsPaused(), isPaused); 72 } 73 74 /** 75 * @tc.name: SetIsInTitle_0001 76 * @tc.desc: Test isInTitle_ parameters. 77 * @tc.type: FUNC 78 * @tc.require: issue 79 */ 80 HWTEST_F(NotificationTimeTest, SetIsInTitle_0001, Function | SmallTest | Level1) 81 { 82 auto rrc = std::make_shared<NotificationTime>(); 83 bool isInTitle = true; 84 rrc->SetIsInTitle(isInTitle); 85 EXPECT_EQ(rrc->GetIsInTitle(), isInTitle); 86 } 87 88 /** 89 * @tc.name: Dump_00001 90 * @tc.desc: Test buttonNames_ dump. 91 * @tc.type: FUNC 92 * @tc.require: issue 93 */ 94 HWTEST_F(NotificationTimeTest, Dump_00001, Function | SmallTest | Level1) 95 { 96 auto rrc = std::make_shared<NotificationTime>(); 97 int32_t initialTime = 1; 98 rrc->SetInitialTime(initialTime); 99 bool isCountDown = true; 100 rrc->SetIsCountDown(isCountDown); 101 bool isPaused = true; 102 rrc->SetIsPaused(isPaused); 103 bool isInTitle = true; 104 rrc->SetIsInTitle(isInTitle); 105 EXPECT_EQ(rrc->Dump(), "Time{ " 106 "initialTime = " + std::to_string(initialTime) + 107 ", isCountDown = " + std::to_string(isCountDown) + 108 ", isPaused = " + std::to_string(isPaused) + 109 ", isInTitle = " + std::to_string(isInTitle) + 110 " }"); 111 } 112 113 /** 114 * @tc.name: FromJson_00001 115 * @tc.desc: Test FromJson parameters. 116 * @tc.type: FUNC 117 * @tc.require: issue 118 */ 119 HWTEST_F(NotificationTimeTest, FromJson_00001, Function | SmallTest | Level1) 120 { 121 auto rrc = std::make_shared<NotificationTime>(); 122 nlohmann::json jsonObject = nlohmann::json{"initialTime", "isCountDown", "isPaused", "isInTitle"}; 123 EXPECT_EQ(jsonObject.is_object(), false); 124 EXPECT_EQ(rrc->FromJson(jsonObject), nullptr); 125 } 126 127 /** 128 * @tc.name: FromJson_00002 129 * @tc.desc: Test FromJson parameters. 130 * @tc.type: FUNC 131 * @tc.require: issue 132 */ 133 HWTEST_F(NotificationTimeTest, FromJson_00002, Function | SmallTest | Level1) 134 { 135 auto rrc = std::make_shared<NotificationTime>(); 136 nlohmann::json jsonObject = nlohmann::json{{"initialTime", 60}, {"isCountDown", false}, 137 {"isPaused", false}, {"isInTitle", false}}; 138 EXPECT_EQ(jsonObject.is_object(), true); 139 EXPECT_NE(rrc->FromJson(jsonObject), nullptr); 140 } 141 142 /** 143 * @tc.name: Marshalling_00001 144 * @tc.desc: Test Marshalling parameters. 145 * @tc.type: FUNC 146 * @tc.require: issueI5WBBH 147 */ 148 HWTEST_F(NotificationTimeTest, Marshalling_00001, Function | SmallTest | Level1) 149 { 150 Parcel parcel; 151 auto rrc = std::make_shared<NotificationTime>(); 152 EXPECT_EQ(rrc->Marshalling(parcel), true); 153 } 154 155 /** 156 * @tc.name: Unmarshalling_00001 157 * @tc.desc: Test Unmarshalling parameters. 158 * @tc.type: FUNC 159 * @tc.require: issueI5WBBH 160 */ 161 HWTEST_F(NotificationTimeTest, Unmarshalling_00001, Function | SmallTest | Level1) 162 { 163 bool unmarshalling = true; 164 Parcel parcel; 165 std::shared_ptr<NotificationTime> result = 166 std::make_shared<NotificationTime>(); 167 168 if (nullptr != result) { 169 if (nullptr == result->Unmarshalling(parcel)) { 170 unmarshalling = false; 171 } 172 } 173 EXPECT_EQ(unmarshalling, true); 174 } 175 } 176 } 177