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 #include "notification_disable.h" 19 20 using namespace testing::ext; 21 namespace OHOS { 22 namespace Notification { 23 class NotificationDisableTest : public testing::Test { 24 public: SetUpTestCase()25 static void SetUpTestCase() {} TearDownTestCase()26 static void TearDownTestCase() {} SetUp()27 void SetUp() {} TearDown()28 void TearDown() {} 29 }; 30 31 /** 32 * @tc.name: GetDisabled_0100 33 * @tc.desc: Test GetDisabled. 34 * @tc.type: FUNC 35 */ 36 HWTEST_F(NotificationDisableTest, GetDisabled_0100, Function | SmallTest | Level1) 37 { 38 NotificationDisable notificationDisable; 39 notificationDisable.SetDisabled(true); 40 EXPECT_TRUE(notificationDisable.GetDisabled()); 41 } 42 43 /** 44 * @tc.name: GetDisabled_0200 45 * @tc.desc: Test GetDisabled. 46 * @tc.type: FUNC 47 */ 48 HWTEST_F(NotificationDisableTest, GetDisabled_0200, Function | SmallTest | Level1) 49 { 50 NotificationDisable notificationDisable; 51 notificationDisable.SetDisabled(false); 52 EXPECT_FALSE(notificationDisable.GetDisabled()); 53 } 54 55 /** 56 * @tc.name: GetBundleList_0100 57 * @tc.desc: Test GetBundleList. 58 * @tc.type: FUNC 59 */ 60 HWTEST_F(NotificationDisableTest, GetBundleList_0100, Function | SmallTest | Level1) 61 { 62 NotificationDisable notificationDisable; 63 std::vector<std::string> bundleList = { "com.example.app" }; 64 notificationDisable.SetBundleList(bundleList); 65 ASSERT_EQ(notificationDisable.GetBundleList(), bundleList); 66 } 67 68 /** 69 * @tc.name: Marshalling_0100 70 * @tc.desc: Test Marshalling. 71 * @tc.type: FUNC 72 */ 73 HWTEST_F(NotificationDisableTest, Marshalling_0100, Function | SmallTest | Level1) 74 { 75 Parcel parcel; 76 auto rrc = std::make_shared<NotificationDisable>(); 77 EXPECT_TRUE(rrc->Marshalling(parcel)); 78 } 79 80 /** 81 * @tc.name: ReadFromParcel_0100 82 * @tc.desc: Test ReadFromParcel. 83 * @tc.type: FUNC 84 */ 85 HWTEST_F(NotificationDisableTest, ReadFromParcel_0100, Function | SmallTest | Level1) 86 { 87 Parcel parcel; 88 auto rrc = std::make_shared<NotificationDisable>(); 89 EXPECT_TRUE(rrc->ReadFromParcel(parcel)); 90 } 91 92 /** 93 * @tc.name: Unmarshalling_0100 94 * @tc.desc: Test Unmarshalling. 95 * @tc.type: FUNC 96 */ 97 HWTEST_F(NotificationDisableTest, Unmarshalling_0100, Function | SmallTest | Level1) 98 { 99 bool unmarshalling = true; 100 Parcel parcel; 101 auto rrc = std::make_shared<NotificationDisable>(); 102 if (nullptr != rrc) { 103 if (nullptr == rrc->Unmarshalling(parcel)) { 104 unmarshalling = false; 105 } 106 } 107 EXPECT_TRUE(unmarshalling); 108 } 109 110 /** 111 * @tc.name: Marshalling_0200 112 * @tc.desc: Test Marshalling_0200. 113 * @tc.type: FUNC 114 */ 115 HWTEST_F(NotificationDisableTest, Marshalling_0200, Function | SmallTest | Level1) 116 { 117 NotificationDisable notificationDisable; 118 std::vector<std::string> bundleList; 119 120 for (auto i = 0; i <= 1000; ++i) { 121 bundleList.push_back("123"); 122 } 123 notificationDisable.SetBundleList(bundleList); 124 125 Parcel parcel; 126 auto res = notificationDisable.Marshalling(parcel); 127 ASSERT_FALSE(res); 128 } 129 130 /** 131 * @tc.name: Marshalling_0100 132 * @tc.desc: Test Marshalling_0100. 133 * @tc.type: FUNC 134 */ 135 HWTEST_F(NotificationDisableTest, FromJson_0100, Function | SmallTest | Level1) 136 { 137 NotificationDisable notificationDisable; 138 std::vector<std::string> bundleList; 139 140 std::string jsonObjString = ""; 141 notificationDisable.FromJson(jsonObjString); 142 ASSERT_FALSE(notificationDisable.GetDisabled()); 143 } 144 145 /** 146 * @tc.name: GetUserId_0100 147 * @tc.desc: Test GetUserId. 148 * @tc.type: FUNC 149 */ 150 HWTEST_F(NotificationDisableTest, GetUserId_0100, Function | SmallTest | Level1) 151 { 152 NotificationDisable notificationDisable; 153 notificationDisable.SetUserId(1); 154 EXPECT_EQ(notificationDisable.GetUserId(), 1); 155 } 156 } 157 } 158