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 "authorization_dialog.h"
19 #include "inject_notice_manager.h"
20 #include "message_option.h"
21 #include "mmi_log.h"
22
23 #undef MMI_LOG_TAG
24 #define MMI_LOG_TAG "InjectNoticeManagerTest"
25
26 namespace OHOS {
27 namespace MMI {
28 namespace {
29 using namespace testing::ext;
30 } // namespace
31
32 class InjectNoticeManagerTest : public testing::Test {
33 public:
SetUpTestCase(void)34 static void SetUpTestCase(void) {}
TearDownTestCase(void)35 static void TearDownTestCase(void) {}
SetUp()36 void SetUp() {}
TearDown()37 void TearDown() {}
38 };
39
40 class AuthorizationDialogTest : public testing::Test {
41 public:
SetUpTestCase(void)42 static void SetUpTestCase(void) {}
TearDownTestCase(void)43 static void TearDownTestCase(void) {}
SetUp()44 void SetUp() {}
TearDown()45 void TearDown() {}
46 };
47
48 /**
49 * @tc.name: AuthorizationDialogTest_ConnectSystemUi
50 * @tc.desc: Test ConnectSystemUi
51 * @tc.type: FUNC
52 * @tc.require:
53 */
HWTEST_F(AuthorizationDialogTest, AuthorizationDialogTest_ConnectSystemUi, TestSize.Level1)54 HWTEST_F(AuthorizationDialogTest, AuthorizationDialogTest_ConnectSystemUi, TestSize.Level1)
55 {
56 CALL_TEST_DEBUG;
57 AuthorizationDialog dialog;
58 EXPECT_FALSE(dialog.ConnectSystemUi());
59 }
60
61 /**
62 * @tc.name: InjectNoticeManagerTest_StartNoticeAbility
63 * @tc.desc: Test StartNoticeAbility
64 * @tc.type: FUNC
65 * @tc.require:
66 */
HWTEST_F(InjectNoticeManagerTest, InjectNoticeManagerTest_StartNoticeAbility, TestSize.Level1)67 HWTEST_F(InjectNoticeManagerTest, InjectNoticeManagerTest_StartNoticeAbility, TestSize.Level1)
68 {
69 CALL_TEST_DEBUG;
70 InjectNoticeManager injectNoticeMgr;
71 injectNoticeMgr.isStartSrv_ = false;
72 EXPECT_FALSE(injectNoticeMgr.StartNoticeAbility());
73 }
74
75 /**
76 * @tc.name: InjectNoticeManagerTest_ConnectNoticeSrv
77 * @tc.desc: Test ConnectNoticeSrv
78 * @tc.type: FUNC
79 * @tc.require:
80 */
HWTEST_F(InjectNoticeManagerTest, InjectNoticeManagerTest_ConnectNoticeSrv, TestSize.Level1)81 HWTEST_F(InjectNoticeManagerTest, InjectNoticeManagerTest_ConnectNoticeSrv, TestSize.Level1)
82 {
83 CALL_TEST_DEBUG;
84 InjectNoticeManager injectNoticeMgr;
85 injectNoticeMgr.connectionCallback_ = new (std::nothrow) InjectNoticeManager::InjectNoticeConnection;
86 ASSERT_NE(injectNoticeMgr.connectionCallback_, nullptr);
87 injectNoticeMgr.connectionCallback_->isConnected_ = true;
88 EXPECT_TRUE(injectNoticeMgr.ConnectNoticeSrv());
89 injectNoticeMgr.connectionCallback_->isConnected_ = false;
90 EXPECT_FALSE(injectNoticeMgr.ConnectNoticeSrv());
91 }
92
93 /**
94 * @tc.name: AuthorizationDialogTest_ConnectSystemUi_002
95 * @tc.desc: Test ConnectSystemUi
96 * @tc.type: FUNC
97 * @tc.require:
98 */
HWTEST_F(AuthorizationDialogTest, AuthorizationDialogTest_ConnectSystemUi_002, TestSize.Level1)99 HWTEST_F(AuthorizationDialogTest, AuthorizationDialogTest_ConnectSystemUi_002, TestSize.Level1)
100 {
101 CALL_TEST_DEBUG;
102 AuthorizationDialog dialog;
103 ASSERT_NE(dialog.dialogConnectionCallback_, nullptr);
104 bool ret = dialog.ConnectSystemUi();
105 ASSERT_TRUE(ret);
106 }
107
108 /**
109 * @tc.name: AuthorizationDialogTest_OnAbilityConnectDone_001
110 * @tc.desc: Test OnAbilityConnectDone
111 * @tc.type: FUNC
112 * @tc.require:
113 */
HWTEST_F(AuthorizationDialogTest, AuthorizationDialogTest_OnAbilityConnectDone_001, TestSize.Level1)114 HWTEST_F(AuthorizationDialogTest, AuthorizationDialogTest_OnAbilityConnectDone_001, TestSize.Level1)
115 {
116 CALL_TEST_DEBUG;
117 AuthorizationDialog::DialogAbilityConnection conn;
118 AppExecFwk::ElementName element;
119 sptr<IRemoteObject> remoteObject;
120 int resultCode = 0;
121 ASSERT_NO_FATAL_FAILURE(conn.OnAbilityConnectDone(element, remoteObject, resultCode));
122 }
123
124 /**
125 * @tc.name: InjectNoticeManagerTest_StartNoticeAbility_002
126 * @tc.desc: Test StartNoticeAbility
127 * @tc.type: FUNC
128 * @tc.require:
129 */
HWTEST_F(InjectNoticeManagerTest, InjectNoticeManagerTest_StartNoticeAbility_002, TestSize.Level1)130 HWTEST_F(InjectNoticeManagerTest, InjectNoticeManagerTest_StartNoticeAbility_002, TestSize.Level1)
131 {
132 CALL_TEST_DEBUG;
133 InjectNoticeManager injectNoticeMgr;
134 injectNoticeMgr.isStartSrv_ = true;
135 bool ret = injectNoticeMgr.StartNoticeAbility();
136 ASSERT_TRUE(ret);
137 injectNoticeMgr.isStartSrv_ = false;
138 ret = injectNoticeMgr.StartNoticeAbility();
139 ASSERT_TRUE(ret);
140 }
141
142 /**
143 * @tc.name: InjectNoticeManagerTest_ConnectNoticeSrv_002
144 * @tc.desc: Test ConnectNoticeSrv
145 * @tc.type: FUNC
146 * @tc.require:
147 */
HWTEST_F(InjectNoticeManagerTest, InjectNoticeManagerTest_ConnectNoticeSrv_002, TestSize.Level1)148 HWTEST_F(InjectNoticeManagerTest, InjectNoticeManagerTest_ConnectNoticeSrv_002, TestSize.Level1)
149 {
150 CALL_TEST_DEBUG;
151 InjectNoticeManager injectNoticeMgr;
152 injectNoticeMgr.connectionCallback_ = new (std::nothrow) InjectNoticeManager::InjectNoticeConnection;
153 ASSERT_NE(injectNoticeMgr.connectionCallback_, nullptr);
154 injectNoticeMgr.connectionCallback_->isConnected_ = true;
155 bool ret = injectNoticeMgr.ConnectNoticeSrv();
156 ASSERT_TRUE(ret);
157 injectNoticeMgr.connectionCallback_->isConnected_ = false;
158 ret = injectNoticeMgr.ConnectNoticeSrv();
159 ASSERT_TRUE(ret);
160 }
161
162 /**
163 * @tc.name: InjectNoticeManagerTest_OnAbilityConnectDone_002
164 * @tc.desc: Test OnAbilityConnectDone
165 * @tc.type: FUNC
166 * @tc.require:
167 */
HWTEST_F(InjectNoticeManagerTest, InjectNoticeManagerTest_OnAbilityConnectDone_002, TestSize.Level1)168 HWTEST_F(InjectNoticeManagerTest, InjectNoticeManagerTest_OnAbilityConnectDone_002, TestSize.Level1)
169 {
170 CALL_TEST_DEBUG;
171 InjectNoticeManager::InjectNoticeConnection connection;
172 AppExecFwk::ElementName element;
173 sptr<IRemoteObject> remoteObject;
174 int resultCode = 0;
175 ASSERT_NO_FATAL_FAILURE(connection.OnAbilityConnectDone(element, remoteObject, resultCode));
176 }
177
178 /**
179 * @tc.name: InjectNoticeManagerTest_SendNotice_001
180 * @tc.desc: Test SendNotice
181 * @tc.type: FUNC
182 * @tc.require:
183 */
HWTEST_F(InjectNoticeManagerTest, InjectNoticeManagerTest_SendNotice_001, TestSize.Level1)184 HWTEST_F(InjectNoticeManagerTest, InjectNoticeManagerTest_SendNotice_001, TestSize.Level1)
185 {
186 CALL_TEST_DEBUG;
187 InjectNoticeManager::InjectNoticeConnection connection;
188 InjectNoticeInfo noticeInfo;
189 noticeInfo.pid = 1;
190 bool result = connection.InjectNoticeConnection::SendNotice(noticeInfo);
191 EXPECT_FALSE(result);
192 }
193
194 /**
195 * @tc.name: InjectNoticeManagerTest_SendNotice_002
196 * @tc.desc: Test SendNotice
197 * @tc.type: FUNC
198 * @tc.require:
199 */
HWTEST_F(InjectNoticeManagerTest, InjectNoticeManagerTest_SendNotice_002, TestSize.Level1)200 HWTEST_F(InjectNoticeManagerTest, InjectNoticeManagerTest_SendNotice_002, TestSize.Level1)
201 {
202 CALL_TEST_DEBUG;
203 InjectNoticeManager::InjectNoticeConnection connection;
204 InjectNoticeInfo noticeInfo;
205 noticeInfo.pid = -1;
206 bool result = connection.InjectNoticeConnection::SendNotice(noticeInfo);
207 EXPECT_FALSE(result);
208 }
209
210 /**
211 * @tc.name: InjectNoticeManagerTest_CancelNotice_001
212 * @tc.desc: Test CancelNotice
213 * @tc.type: FUNC
214 * @tc.require:
215 */
HWTEST_F(InjectNoticeManagerTest, InjectNoticeManagerTest_CancelNotice_001, TestSize.Level1)216 HWTEST_F(InjectNoticeManagerTest, InjectNoticeManagerTest_CancelNotice_001, TestSize.Level1)
217 {
218 CALL_TEST_DEBUG;
219 InjectNoticeManager::InjectNoticeConnection connection;
220 InjectNoticeInfo noticeInfo;
221 noticeInfo.pid = 1;
222 bool result = connection.InjectNoticeConnection::CancelNotice(noticeInfo);
223 EXPECT_FALSE(result);
224 }
225
226 /**
227 * @tc.name: InjectNoticeManagerTest_CancelNotice_002
228 * @tc.desc: Test CancelNotice
229 * @tc.type: FUNC
230 * @tc.require:
231 */
HWTEST_F(InjectNoticeManagerTest, InjectNoticeManagerTest_CancelNotice_002, TestSize.Level1)232 HWTEST_F(InjectNoticeManagerTest, InjectNoticeManagerTest_CancelNotice_002, TestSize.Level1)
233 {
234 CALL_TEST_DEBUG;
235 InjectNoticeManager::InjectNoticeConnection connection;
236 InjectNoticeInfo noticeInfo;
237 noticeInfo.pid = -1;
238 bool result = connection.InjectNoticeConnection::CancelNotice(noticeInfo);
239 EXPECT_FALSE(result);
240 }
241 } // namespace MMI
242 } // namespace OHOS