1 /* 2 * Copyright (c) 2024 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 "ans_log_wrapper.h" 19 20 #define private public 21 #define protected public 22 #include "notification_do_not_disturb_profile.h" 23 #undef private 24 #undef protected 25 26 using namespace testing::ext; 27 namespace OHOS { 28 namespace Notification { 29 class NotificationDoNotDisturbProfileTest : 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: SetProfileId_0100 39 * @tc.desc: test SetProfileId parameters. 40 * @tc.type: FUNC 41 */ 42 HWTEST_F(NotificationDoNotDisturbProfileTest, SetProfileId_0100, TestSize.Level1) 43 { 44 int32_t id = 1; 45 std::string name = "name"; 46 std::vector<NotificationBundleOption> trustlist; 47 NotificationBundleOption bundleOption; 48 trustlist.emplace_back(bundleOption); 49 auto rrc = std::make_shared<NotificationDoNotDisturbProfile>(id, name, trustlist); 50 rrc->SetProfileId(2); 51 EXPECT_EQ(rrc->GetProfileId(), 2); 52 } 53 54 /** 55 * @tc.name: SetProfileName_0100 56 * @tc.desc: test SetProfileName parameters. 57 * @tc.type: FUNC 58 */ 59 HWTEST_F(NotificationDoNotDisturbProfileTest, SetProfileName_0100, TestSize.Level1) 60 { 61 int32_t id = 1; 62 std::string name = "name"; 63 std::vector<NotificationBundleOption> trustlist; 64 NotificationBundleOption bundleOption; 65 trustlist.emplace_back(bundleOption); 66 auto rrc = std::make_shared<NotificationDoNotDisturbProfile>(id, name, trustlist); 67 rrc->SetProfileName("newName"); 68 EXPECT_EQ(rrc->GetProfileName(), "newName"); 69 } 70 71 /** 72 * @tc.name: SetProfileTrustList_0100 73 * @tc.desc: test SetProfileTrustList parameters. 74 * @tc.type: FUNC 75 */ 76 HWTEST_F(NotificationDoNotDisturbProfileTest, SetProfileTrustList_0100, TestSize.Level1) 77 { 78 int32_t id = 1; 79 std::string name = "name"; 80 std::vector<NotificationBundleOption> trustlist; 81 NotificationBundleOption bundleOption; 82 trustlist.emplace_back(bundleOption); 83 auto rrc = std::make_shared<NotificationDoNotDisturbProfile>(id, name, trustlist); 84 std::vector<NotificationBundleOption> myTrustlist; 85 bundleOption.SetBundleName("bundleName"); 86 bundleOption.SetUid(1); 87 myTrustlist.emplace_back(bundleOption); 88 rrc->SetProfileTrustList(myTrustlist); 89 auto getTrust = rrc->GetProfileTrustList(); 90 EXPECT_EQ(getTrust[0].GetUid(), myTrustlist[0].GetUid()); 91 EXPECT_EQ(getTrust[0].GetBundleName(), myTrustlist[0].GetBundleName()); 92 } 93 94 /** 95 * @tc.name: Marshalling_0100 96 * @tc.desc: test Marshalling when it can run to end. 97 * @tc.type: FUNC 98 */ 99 HWTEST_F(NotificationDoNotDisturbProfileTest, Marshalling_0100, TestSize.Level1) 100 { 101 int32_t id = 1; 102 std::string name = "name"; 103 std::vector<NotificationBundleOption> trustlist; 104 NotificationBundleOption bundleOption; 105 trustlist.emplace_back(bundleOption); 106 auto rrc = std::make_shared<NotificationDoNotDisturbProfile>(id, name, trustlist); 107 Parcel parcel; 108 auto res = rrc->Marshalling(parcel); 109 EXPECT_EQ(res, true); 110 } 111 112 /** 113 * @tc.name: ReadFromParcel_0100 114 * @tc.desc: test it when trustlist_ emplace success. 115 * @tc.type: FUNC 116 */ 117 HWTEST_F(NotificationDoNotDisturbProfileTest, ReadFromParcel_0100, TestSize.Level1) 118 { 119 int32_t id = 1; 120 std::string name = "name"; 121 std::vector<NotificationBundleOption> trustlist; 122 NotificationBundleOption bundleOption; 123 trustlist.emplace_back(bundleOption); 124 auto rrc = std::make_shared<NotificationDoNotDisturbProfile>(id, name, trustlist); 125 126 Parcel parcel; 127 parcel.WriteUint32(10); 128 auto res = rrc->ReadFromParcel(parcel); 129 sptr<NotificationBundleOption> notification = new (std::nothrow) NotificationBundleOption(); 130 parcel.WriteParcelable(notification); 131 EXPECT_EQ(res, true); 132 } 133 134 /** 135 * @tc.name: ReadFromParcel_0200 136 * @tc.desc: test it when trustlist_ emplace success. 137 * @tc.type: FUNC 138 */ 139 HWTEST_F(NotificationDoNotDisturbProfileTest, ReadFromParcel_0200, TestSize.Level1) 140 { 141 int32_t id = 1; 142 std::string name = "name"; 143 std::vector<NotificationBundleOption> trustlist; 144 NotificationBundleOption bundleOption; 145 trustlist.emplace_back(bundleOption); 146 auto rrc = std::make_shared<NotificationDoNotDisturbProfile>(id, name, trustlist); 147 148 Parcel parcel; 149 parcel.WriteUint32(10); 150 sptr<NotificationBundleOption> notification = new (std::nothrow) NotificationBundleOption(); 151 parcel.WriteParcelable(notification); 152 auto res = rrc->ReadFromParcel(parcel); 153 EXPECT_EQ(res, true); 154 } 155 156 /** 157 * @tc.name: Unmarshalling_0100 158 * @tc.desc: test it when Unmarshalling success. 159 * @tc.type: FUNC 160 */ 161 HWTEST_F(NotificationDoNotDisturbProfileTest, Unmarshalling_0100, TestSize.Level1) 162 { 163 bool unmarshalling = true; 164 Parcel parcel; 165 int32_t id = 1; 166 std::string name = "name"; 167 std::vector<NotificationBundleOption> trustlist; 168 NotificationBundleOption bundleOption; 169 trustlist.emplace_back(bundleOption); 170 std::shared_ptr<NotificationDoNotDisturbProfile> result = 171 std::make_shared<NotificationDoNotDisturbProfile>(id, name, trustlist); 172 if (nullptr != result) { 173 if (nullptr == result->Unmarshalling(parcel)) { 174 unmarshalling = false; 175 } 176 } 177 EXPECT_EQ(unmarshalling, true); 178 } 179 } // namespace Notification 180 } // namespace OHOS 181