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"; 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: Marshalling_00001 92 * @tc.desc: Test Marshalling parameters. 93 * @tc.type: FUNC 94 * @tc.require: issueI5WBBH 95 */ 96 HWTEST_F(NotificationFlagsTest, Marshalling_00001, Function | SmallTest | Level1) 97 { 98 Parcel parcel; 99 auto rrc = std::make_shared<NotificationFlags>(); 100 EXPECT_EQ(rrc->Marshalling(parcel), true); 101 } 102 103 /** 104 * @tc.name: Unmarshalling_00001 105 * @tc.desc: Test Unmarshalling parameters. 106 * @tc.type: FUNC 107 * @tc.require: issueI5WBBH 108 */ 109 HWTEST_F(NotificationFlagsTest, Unmarshalling_001, Function | SmallTest | Level1) 110 { 111 bool unmarshalling = true; 112 Parcel parcel; 113 std::shared_ptr<NotificationFlags> result = 114 std::make_shared<NotificationFlags>(); 115 116 if (nullptr != result) { 117 if (nullptr == result->Unmarshalling(parcel)) { 118 unmarshalling = false; 119 } 120 } 121 EXPECT_EQ(unmarshalling, true); 122 } 123 124 /** 125 * @tc.name: ReadFromParcel_00001 126 * @tc.desc: Test ReadFromParcel parameters. 127 * @tc.type: FUNC 128 * @tc.require: issueI5WBBH 129 */ 130 HWTEST_F(NotificationFlagsTest, ReadFromParcel_00001, Function | SmallTest | Level1) 131 { 132 Parcel parcel; 133 auto rrc = std::make_shared<NotificationFlags>(); 134 EXPECT_EQ(rrc->ReadFromParcel(parcel), true); 135 } 136 } 137 }