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 #include <string> 18 19 #define private public 20 #define protected public 21 #include "notification_subscribe_info.h" 22 #undef private 23 #undef protected 24 25 using namespace testing::ext; 26 namespace OHOS { 27 namespace Notification { 28 class NotificationSubscribeInfoTest : public testing::Test { 29 public: SetUpTestCase()30 static void SetUpTestCase() {} TearDownTestCase()31 static void TearDownTestCase() {} SetUp()32 void SetUp() {} TearDown()33 void TearDown() {} 34 }; 35 36 /** 37 * @tc.name: AddAppName_00001 38 * @tc.desc: Test AddAppName parameters. 39 * @tc.type: FUNC 40 * @tc.require: issueI5WRQ2 41 */ 42 HWTEST_F(NotificationSubscribeInfoTest, AddAppName_00001, Function | SmallTest | Level1) 43 { 44 std::string appName = "AppName"; 45 NotificationSubscribeInfo subscribeInfo; 46 auto rrc = std::make_shared<NotificationSubscribeInfo>(subscribeInfo); 47 rrc->AddAppName(appName); 48 std::vector<std::string> result = rrc->GetAppNames(); 49 EXPECT_EQ(result.size(), 1); 50 } 51 52 /** 53 * @tc.name: AddAppNames_00001 54 * @tc.desc: Test AddAppNames parameters. 55 * @tc.type: FUNC 56 * @tc.require: issueI5WRQ2 57 */ 58 HWTEST_F(NotificationSubscribeInfoTest, AddAppNames_00001, Function | SmallTest | Level1) 59 { 60 std::vector<std::string> appNames; 61 NotificationSubscribeInfo subscribeInfo; 62 auto rrc = std::make_shared<NotificationSubscribeInfo>(subscribeInfo); 63 rrc->AddAppNames(appNames); 64 std::vector<std::string> result = rrc->GetAppNames(); 65 EXPECT_EQ(result.size(), 0); 66 } 67 68 /** 69 * @tc.name: AddAppUserId_00001 70 * @tc.desc: Test AddAppUserId parameters. 71 * @tc.type: FUNC 72 * @tc.require: issueI5WRQ2 73 */ 74 HWTEST_F(NotificationSubscribeInfoTest, AddAppUserId_00001, Function | SmallTest | Level1) 75 { 76 int32_t userId = 10; 77 NotificationSubscribeInfo subscribeInfo; 78 auto rrc = std::make_shared<NotificationSubscribeInfo>(subscribeInfo); 79 rrc->AddAppUserId(userId); 80 EXPECT_EQ(rrc->GetAppUserId(), userId); 81 } 82 83 /** 84 * @tc.name: Marshalling_00001 85 * @tc.desc: Test Marshalling parameters. 86 * @tc.type: FUNC 87 * @tc.require: issueI5WRQ2 88 */ 89 HWTEST_F(NotificationSubscribeInfoTest, Marshalling_00001, Function | SmallTest | Level1) 90 { 91 Parcel parcel; 92 NotificationSubscribeInfo subscribeInfo; 93 auto rrc = std::make_shared<NotificationSubscribeInfo>(subscribeInfo); 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: issueI5WRQ2 102 */ 103 HWTEST_F(NotificationSubscribeInfoTest, Unmarshalling_001, Function | SmallTest | Level1) 104 { 105 bool unmarshalling = true; 106 Parcel parcel; 107 NotificationSubscribeInfo subscribeInfo; 108 std::shared_ptr<NotificationSubscribeInfo> result = 109 std::make_shared<NotificationSubscribeInfo>(subscribeInfo); 110 result->Marshalling(parcel); 111 112 if (nullptr != result) { 113 if (nullptr == result->Unmarshalling(parcel)) { 114 unmarshalling = false; 115 } 116 } 117 EXPECT_EQ(unmarshalling, true); 118 } 119 120 /** 121 * @tc.name: ReadFromParcel_00001 122 * @tc.desc: Test ReadFromParcel parameters. 123 * @tc.type: FUNC 124 * @tc.require: issueI5WRQ2 125 */ 126 HWTEST_F(NotificationSubscribeInfoTest, ReadFromParcel_00001, Function | SmallTest | Level1) 127 { 128 Parcel parcel; 129 NotificationSubscribeInfo subscribeInfo; 130 auto rrc = std::make_shared<NotificationSubscribeInfo>(subscribeInfo); 131 rrc->Marshalling(parcel); 132 EXPECT_EQ(rrc->ReadFromParcel(parcel), true); 133 } 134 135 /** 136 * @tc.name: AddDeviceType_00001 137 * @tc.desc: Test AddDeviceType. 138 * @tc.type: FUNC 139 * @tc.require: issueI5WRQ2 140 */ 141 HWTEST_F(NotificationSubscribeInfoTest, AddDeviceType_00001, Function | SmallTest | Level1) 142 { 143 std::string deviceType = "test"; 144 NotificationSubscribeInfo subscribeInfo; 145 auto rrc = std::make_shared<NotificationSubscribeInfo>(subscribeInfo); 146 rrc->AddDeviceType(deviceType); 147 EXPECT_EQ(rrc->GetDeviceType(), deviceType); 148 } 149 150 /** 151 * @tc.name: Dump_00001 152 * @tc.desc: Test Dump. 153 * @tc.type: FUNC 154 * @tc.require: issueI5WRQ2 155 */ 156 HWTEST_F(NotificationSubscribeInfoTest, Dump_00001, Function | SmallTest | Level1) 157 { 158 std::string deviceType = "test"; 159 std::string appName = "AppName"; 160 int32_t userId = 100; 161 NotificationSubscribeInfo subscribeInfo; 162 auto rrc = std::make_shared<NotificationSubscribeInfo>(subscribeInfo); 163 rrc->AddDeviceType(deviceType); 164 rrc->AddAppName(appName); 165 rrc->AddAppUserId(userId); 166 std::string res = "NotificationSubscribeInfo{ " 167 "appNames = [" + appName + ", ]" + 168 "deviceType = " + deviceType + 169 "userId = " + std::to_string(userId) + 170 " }"; 171 EXPECT_EQ(res, rrc->Dump()); 172 } 173 } 174 } 175