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_bundle_option.h" 21 #undef private 22 #undef protected 23 24 using namespace testing::ext; 25 namespace OHOS { 26 namespace Notification { 27 class NotificationBundleOptionTest : 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: SetBundleName_00001 37 * @tc.desc: Test SetBundleName parameters. 38 * @tc.type: FUNC 39 * @tc.require: issueI5WBBH 40 */ 41 HWTEST_F(NotificationBundleOptionTest, SetBundleName_00001, Function | SmallTest | Level1) 42 { 43 std::string bundleName = "BundleName"; 44 std::string bundleName1 = "BundleName1"; 45 int32_t uid = 10; 46 auto rrc = std::make_shared<NotificationBundleOption>(bundleName, uid); 47 rrc->SetBundleName(bundleName1); 48 EXPECT_EQ(rrc->GetBundleName(), bundleName1); 49 } 50 51 /** 52 * @tc.name: SetUid_00001 53 * @tc.desc: Test SetUid parameters. 54 * @tc.type: FUNC 55 * @tc.require: issueI5WBBH 56 */ 57 HWTEST_F(NotificationBundleOptionTest, SetUid_00001, Function | SmallTest | Level1) 58 { 59 std::string bundleName = "BundleName"; 60 int32_t uid = 10; 61 int32_t uid1 = 20; 62 auto rrc = std::make_shared<NotificationBundleOption>(bundleName, uid); 63 rrc->SetUid(uid1); 64 EXPECT_EQ(rrc->GetUid(), uid1); 65 } 66 67 /** 68 * @tc.name: Dump_00001 69 * @tc.desc: Test Dump parameters. 70 * @tc.type: FUNC 71 * @tc.require: issueI5WBBH 72 */ 73 HWTEST_F(NotificationBundleOptionTest, Dump_00001, Function | SmallTest | Level1) 74 { 75 std::string bundleName = "BundleName"; 76 int32_t uid = 10; 77 auto rrc = std::make_shared<NotificationBundleOption>(bundleName, uid); 78 std::string ret = 79 "NotificationBundleOption{ bundleName = BundleName, uid = 10, instanceKey = 0, appIndex = -1 }"; 80 EXPECT_EQ(rrc->Dump(), ret); 81 } 82 83 /** 84 * @tc.name: Marshalling_00001 85 * @tc.desc: Test Marshalling parameters. 86 * @tc.type: FUNC 87 * @tc.require: issueI5WBBH 88 */ 89 HWTEST_F(NotificationBundleOptionTest, Marshalling_00001, Function | SmallTest | Level1) 90 { 91 Parcel parcel; 92 std::string bundleName = "BundleName"; 93 int32_t uid = 10; 94 auto rrc = std::make_shared<NotificationBundleOption>(bundleName, uid); 95 EXPECT_EQ(rrc->Marshalling(parcel), true); 96 } 97 98 /** 99 * @tc.name: Unmarshalling_00001 100 * @tc.desc: Test Unmarshalling parameters. 101 * @tc.type: FUNC 102 * @tc.require: issueI5WBBH 103 */ 104 HWTEST_F(NotificationBundleOptionTest, Unmarshalling_001, Function | SmallTest | Level1) 105 { 106 bool unmarshalling = true; 107 Parcel parcel; 108 std::string bundleName = "BundleName"; 109 int32_t uid = 10; 110 std::shared_ptr<NotificationBundleOption> result = 111 std::make_shared<NotificationBundleOption>(bundleName, uid); 112 113 if (nullptr != result) { 114 if (nullptr == result->Unmarshalling(parcel)) { 115 unmarshalling = false; 116 } 117 } 118 EXPECT_EQ(unmarshalling, false); 119 } 120 121 /** 122 * @tc.name: ReadFromParcel_00001 123 * @tc.desc: Test ReadFromParcel parameters. 124 * @tc.type: FUNC 125 * @tc.require: issueI5WBBH 126 */ 127 HWTEST_F(NotificationBundleOptionTest, ReadFromParcel_00001, Function | SmallTest | Level1) 128 { 129 Parcel parcel; 130 std::string bundleName = "BundleName"; 131 int32_t uid = 10; 132 auto rrc = std::make_shared<NotificationBundleOption>(bundleName, uid); 133 EXPECT_EQ(rrc->ReadFromParcel(parcel), false); 134 } 135 136 /** 137 * @tc.name: JsonConvert_00001 138 * @tc.desc: Test json convert 139 * @tc.type: FUNC 140 * @tc.require: issue 141 */ 142 HWTEST_F(NotificationBundleOptionTest, JsonConvert_00001, Function | SmallTest | Level1) 143 { 144 std::string bundleName = "BundleName"; 145 int32_t uid = 10; 146 auto rrc = std::make_shared<NotificationBundleOption>(bundleName, uid); 147 nlohmann::json jsonObject; 148 EXPECT_TRUE(rrc->ToJson(jsonObject)); 149 auto *rrcNew = rrc->FromJson(jsonObject); 150 EXPECT_EQ(rrcNew->GetBundleName(), rrc->GetBundleName()); 151 EXPECT_EQ(rrcNew->GetUid(), rrc->GetUid()); 152 } 153 } // namespace Notification 154 } // namespace OHOS 155