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 = "NotificationBundleOption{ bundleName = BundleName, uid = 10, instanceKey = 0, appIndex = -1 }"; 79 EXPECT_EQ(rrc->Dump(), ret); 80 } 81 82 /** 83 * @tc.name: Marshalling_00001 84 * @tc.desc: Test Marshalling parameters. 85 * @tc.type: FUNC 86 * @tc.require: issueI5WBBH 87 */ 88 HWTEST_F(NotificationBundleOptionTest, Marshalling_00001, Function | SmallTest | Level1) 89 { 90 Parcel parcel; 91 std::string bundleName = "BundleName"; 92 int32_t uid = 10; 93 auto rrc = std::make_shared<NotificationBundleOption>(bundleName, uid); 94 EXPECT_EQ(rrc->Marshalling(parcel), true); 95 } 96 97 /** 98 * @tc.name: Unmarshalling_00001 99 * @tc.desc: Test Unmarshalling parameters. 100 * @tc.type: FUNC 101 * @tc.require: issueI5WBBH 102 */ 103 HWTEST_F(NotificationBundleOptionTest, Unmarshalling_001, Function | SmallTest | Level1) 104 { 105 bool unmarshalling = true; 106 Parcel parcel; 107 std::string bundleName = "BundleName"; 108 int32_t uid = 10; 109 std::shared_ptr<NotificationBundleOption> result = 110 std::make_shared<NotificationBundleOption>(bundleName, uid); 111 112 if (nullptr != result) { 113 if (nullptr == result->Unmarshalling(parcel)) { 114 unmarshalling = false; 115 } 116 } 117 EXPECT_EQ(unmarshalling, false); 118 } 119 120 /** 121 * @tc.name: ReadFromParcel_00001 122 * @tc.desc: Test ReadFromParcel parameters. 123 * @tc.type: FUNC 124 * @tc.require: issueI5WBBH 125 */ 126 HWTEST_F(NotificationBundleOptionTest, ReadFromParcel_00001, Function | SmallTest | Level1) 127 { 128 Parcel parcel; 129 std::string bundleName = "BundleName"; 130 int32_t uid = 10; 131 auto rrc = std::make_shared<NotificationBundleOption>(bundleName, uid); 132 EXPECT_EQ(rrc->ReadFromParcel(parcel), false); 133 } 134 135 /** 136 * @tc.name: JsonConvert_00001 137 * @tc.desc: Test json convert 138 * @tc.type: FUNC 139 * @tc.require: issue 140 */ 141 HWTEST_F(NotificationBundleOptionTest, JsonConvert_00001, Function | SmallTest | Level1) 142 { 143 std::string bundleName = "BundleName"; 144 int32_t uid = 10; 145 auto rrc = std::make_shared<NotificationBundleOption>(bundleName, uid); 146 nlohmann::json jsonObject; 147 EXPECT_TRUE(rrc->ToJson(jsonObject)); 148 auto *rrcNew = rrc->FromJson(jsonObject); 149 EXPECT_EQ(rrcNew->GetBundleName(), rrc->GetBundleName()); 150 EXPECT_EQ(rrcNew->GetUid(), rrc->GetUid()); 151 } 152 } // namespace Notification 153 } // namespace OHOS 154