• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_subscribe_info.h"
21 #undef private
22 #undef protected
23 
24 using namespace testing::ext;
25 namespace OHOS {
26 namespace Notification {
27 class NotificationSubscribeInfoTest : 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: AddAppName_00001
37  * @tc.desc: Test AddAppName parameters.
38  * @tc.type: FUNC
39  * @tc.require: issueI5WRQ2
40  */
41 HWTEST_F(NotificationSubscribeInfoTest, AddAppName_00001, Function | SmallTest | Level1)
42 {
43     std::string appName = "AppName";
44     NotificationSubscribeInfo subscribeInfo;
45     auto rrc = std::make_shared<NotificationSubscribeInfo>(subscribeInfo);
46     rrc->AddAppName(appName);
47     std::vector<std::string> result = rrc->GetAppNames();
48     EXPECT_EQ(result.size(), 1);
49 }
50 
51 /**
52  * @tc.name: AddAppNames_00001
53  * @tc.desc: Test AddAppNames parameters.
54  * @tc.type: FUNC
55  * @tc.require: issueI5WRQ2
56  */
57 HWTEST_F(NotificationSubscribeInfoTest, AddAppNames_00001, Function | SmallTest | Level1)
58 {
59     std::vector<std::string> appNames;
60     NotificationSubscribeInfo subscribeInfo;
61     auto rrc = std::make_shared<NotificationSubscribeInfo>(subscribeInfo);
62     rrc->AddAppNames(appNames);
63     std::vector<std::string> result = rrc->GetAppNames();
64     EXPECT_EQ(result.size(), 0);
65 }
66 
67 /**
68  * @tc.name: AddAppUserId_00001
69  * @tc.desc: Test AddAppUserId parameters.
70  * @tc.type: FUNC
71  * @tc.require: issueI5WRQ2
72  */
73 HWTEST_F(NotificationSubscribeInfoTest, AddAppUserId_00001, Function | SmallTest | Level1)
74 {
75     int32_t userId = 10;
76     NotificationSubscribeInfo subscribeInfo;
77     auto rrc = std::make_shared<NotificationSubscribeInfo>(subscribeInfo);
78     rrc->AddAppUserId(userId);
79     EXPECT_EQ(rrc->GetAppUserId(), userId);
80 }
81 
82 /**
83  * @tc.name: Marshalling_00001
84  * @tc.desc: Test Marshalling parameters.
85  * @tc.type: FUNC
86  * @tc.require: issueI5WRQ2
87  */
88 HWTEST_F(NotificationSubscribeInfoTest, Marshalling_00001, Function | SmallTest | Level1)
89 {
90     Parcel parcel;
91     NotificationSubscribeInfo subscribeInfo;
92     auto rrc = std::make_shared<NotificationSubscribeInfo>(subscribeInfo);
93     EXPECT_EQ(rrc->Marshalling(parcel), true);
94 }
95 
96 /**
97  * @tc.name: Unmarshalling_00001
98  * @tc.desc: Test Unmarshalling parameters.
99  * @tc.type: FUNC
100  * @tc.require: issueI5WRQ2
101  */
102 HWTEST_F(NotificationSubscribeInfoTest, Unmarshalling_001, Function | SmallTest | Level1)
103 {
104     bool unmarshalling = true;
105     Parcel parcel;
106     NotificationSubscribeInfo subscribeInfo;
107     std::shared_ptr<NotificationSubscribeInfo> result =
108     std::make_shared<NotificationSubscribeInfo>(subscribeInfo);
109 
110     if (nullptr != result) {
111         if (nullptr == result->Unmarshalling(parcel)) {
112             unmarshalling = false;
113         }
114     }
115     EXPECT_EQ(unmarshalling, true);
116 }
117 
118 /**
119  * @tc.name: ReadFromParcel_00001
120  * @tc.desc: Test ReadFromParcel parameters.
121  * @tc.type: FUNC
122  * @tc.require: issueI5WRQ2
123  */
124 HWTEST_F(NotificationSubscribeInfoTest, ReadFromParcel_00001, Function | SmallTest | Level1)
125 {
126     Parcel parcel;
127     NotificationSubscribeInfo subscribeInfo;
128     auto rrc = std::make_shared<NotificationSubscribeInfo>(subscribeInfo);
129     EXPECT_EQ(rrc->ReadFromParcel(parcel), true);
130 }
131 }
132 }