• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include <string>
18 
19 #include "module_ipc/service.h"
20 #include "svc_session_manager_throw_mock.h"
21 #include "test_manager.h"
22 
23 namespace OHOS::FileManagement::Backup {
24 using namespace std;
25 using namespace testing;
26 
27 constexpr int32_t SERVICE_ID = 5203;
28 
29 class ServiceThrowTest : public testing::Test {
30 public:
31     static void SetUpTestCase(void);
32     static void TearDownTestCase();
SetUp()33     void SetUp() {};
TearDown()34     void TearDown() {};
35 
36     static inline sptr<Service> service = nullptr;
37     static inline shared_ptr<SvcSessionManagerMock> sessionMock = nullptr;
38 };
39 
SetUpTestCase(void)40 void ServiceThrowTest::SetUpTestCase(void)
41 {
42     GTEST_LOG_(INFO) << "SetUpTestCase enter";
43     service = sptr<Service>(new Service(SERVICE_ID));
44     sessionMock = make_shared<SvcSessionManagerMock>();
45     SvcSessionManagerMock::session = sessionMock;
46 }
47 
TearDownTestCase()48 void ServiceThrowTest::TearDownTestCase()
49 {
50     GTEST_LOG_(INFO) << "TearDownTestCase enter";
51     service = nullptr;
52     SvcSessionManagerMock::session = nullptr;
53     sessionMock = nullptr;
54 }
55 
56 /**
57  * @tc.number: SUB_Service_throw_GetLocalCapabilities_0100
58  * @tc.name: SUB_Service_throw_GetLocalCapabilities_0100
59  * @tc.desc: 测试 GetLocalCapabilities 接口的 catch 分支
60  * @tc.size: MEDIUM
61  * @tc.type: FUNC
62  * @tc.level Level 1
63  * @tc.require: issuesIAC04T
64  */
65 HWTEST_F(ServiceThrowTest, SUB_Service_throw_GetLocalCapabilities_0100, testing::ext::TestSize.Level1)
66 {
67     GTEST_LOG_(INFO) << "ServiceThrowTest-begin SUB_Service_throw_GetLocalCapabilities_0100";
68     try {
69         EXPECT_NE(service, nullptr);
__anon410060db0102() 70         EXPECT_CALL(*sessionMock, IncreaseSessionCnt(_)).WillOnce(Invoke([]() {
71             throw BError(BError::Codes::EXT_THROW_EXCEPTION);
72         }));
73         EXPECT_CALL(*sessionMock, DecreaseSessionCnt(_)).WillOnce(Return());
74         auto ret = service->GetLocalCapabilities();
75         EXPECT_EQ(-ret, BError(BError::Codes::EXT_THROW_EXCEPTION).GetCode());
76 
__anon410060db0202() 77         EXPECT_CALL(*sessionMock, IncreaseSessionCnt(_)).WillOnce(Invoke([]() {
78             throw runtime_error("运行时错误");
79         }));
80         EXPECT_CALL(*sessionMock, DecreaseSessionCnt(_)).WillOnce(Return());
81         ret = service->GetLocalCapabilities();
82         EXPECT_EQ(-ret, EPERM);
83 
__anon410060db0302() 84         EXPECT_CALL(*sessionMock, IncreaseSessionCnt(_)).WillOnce(Invoke([]() {
85             throw "未知错误";
86         }));
87         EXPECT_CALL(*sessionMock, DecreaseSessionCnt(_)).WillOnce(Return());
88         ret = service->GetLocalCapabilities();
89         EXPECT_EQ(-ret, EPERM);
90     } catch (...) {
91         EXPECT_TRUE(false);
92         GTEST_LOG_(INFO) << "ServiceThrowTest-an exception occurred by GetLocalCapabilities.";
93     }
94     GTEST_LOG_(INFO) << "ServiceThrowTest-end SUB_Service_throw_GetLocalCapabilities_0100";
95 }
96 
97 /**
98  * @tc.number: SUB_Service_throw_InitRestoreSession_0100
99  * @tc.name: SUB_Service_throw_InitRestoreSession_0100
100  * @tc.desc: 测试 InitRestoreSession 接口的 catch 分支
101  * @tc.size: MEDIUM
102  * @tc.type: FUNC
103  * @tc.level Level 1
104  * @tc.require: issuesIAC04T
105  */
106 HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitRestoreSession_0100, testing::ext::TestSize.Level1)
107 {
108     GTEST_LOG_(INFO) << "ServiceThrowTest-begin SUB_Service_throw_InitRestoreSession_0100";
109     try {
110         EXPECT_NE(service, nullptr);
__anon410060db0402() 111         EXPECT_CALL(*sessionMock, Active(_)).WillOnce(Invoke([]() {
112             throw BError(BError::Codes::EXT_THROW_EXCEPTION);
113             return 0;
114         }));
115         EXPECT_CALL(*sessionMock, Deactive(_, _)).WillOnce(Return());
116         auto ret = service->InitRestoreSession(nullptr);
117         EXPECT_EQ(ret, BError(BError::Codes::EXT_THROW_EXCEPTION).GetCode());
118 
__anon410060db0502() 119         EXPECT_CALL(*sessionMock, Active(_)).WillOnce(Invoke([]() {
120             throw runtime_error("运行时错误");
121             return 0;
122         }));
123         ret = service->InitRestoreSession(nullptr);
124         EXPECT_EQ(ret, EPERM);
125 
__anon410060db0602() 126         EXPECT_CALL(*sessionMock, Active(_)).WillOnce(Invoke([]() {
127             throw "未知错误";
128             return 0;
129         }));
130         ret = service->InitRestoreSession(nullptr);
131         EXPECT_EQ(ret, EPERM);
132     } catch (...) {
133         EXPECT_TRUE(false);
134         GTEST_LOG_(INFO) << "ServiceThrowTest-an exception occurred by InitRestoreSession.";
135     }
136     GTEST_LOG_(INFO) << "ServiceThrowTest-end SUB_Service_throw_InitRestoreSession_0100";
137 }
138 
139 /**
140  * @tc.number: SUB_Service_throw_InitBackupSession_0100
141  * @tc.name: SUB_Service_throw_InitBackupSession_0100
142  * @tc.desc: 测试 InitBackupSession 接口的 catch 分支
143  * @tc.size: MEDIUM
144  * @tc.type: FUNC
145  * @tc.level Level 1
146  * @tc.require: issuesIAC04T
147  */
148 HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitBackupSession_0100, testing::ext::TestSize.Level1)
149 {
150     GTEST_LOG_(INFO) << "ServiceThrowTest-begin SUB_Service_throw_InitBackupSession_0100";
151     try {
152         EXPECT_NE(service, nullptr);
__anon410060db0702() 153         EXPECT_CALL(*sessionMock, SetMemParaCurSize(_)).WillOnce(Invoke([]() {
154             throw BError(BError::Codes::EXT_THROW_EXCEPTION);
155         }));
156         EXPECT_CALL(*sessionMock, Deactive(_, _)).WillOnce(Return());
157         auto ret = service->InitBackupSession(nullptr);
158         EXPECT_EQ(ret, BError(BError::Codes::EXT_THROW_EXCEPTION).GetCode());
159     } catch (...) {
160         EXPECT_TRUE(false);
161         GTEST_LOG_(INFO) << "ServiceThrowTest-an exception occurred by InitBackupSession.";
162     }
163     GTEST_LOG_(INFO) << "ServiceThrowTest-end SUB_Service_throw_InitBackupSession_0100";
164 }
165 
166 /**
167  * @tc.number: SUB_Service_throw_AppendBundlesRestoreSession_0100
168  * @tc.name: SUB_Service_throw_AppendBundlesRestoreSession_0100
169  * @tc.desc: 测试 AppendBundlesRestoreSession 接口的 catch 分支
170  * @tc.size: MEDIUM
171  * @tc.type: FUNC
172  * @tc.level Level 1
173  * @tc.require: issuesIAC04T
174  */
175 HWTEST_F(ServiceThrowTest, SUB_Service_throw_AppendBundlesRestoreSession_0100, testing::ext::TestSize.Level1)
176 {
177     GTEST_LOG_(INFO) << "ServiceThrowTest-begin SUB_Service_throw_AppendBundlesRestoreSession_0100";
178     try {
179         EXPECT_NE(service, nullptr);
__anon410060db0802() 180         EXPECT_CALL(*sessionMock, IncreaseSessionCnt(_)).WillOnce(Invoke([]() {
181             throw BError(BError::Codes::EXT_THROW_EXCEPTION);
182         }));
183         EXPECT_CALL(*sessionMock, DecreaseSessionCnt(_)).WillOnce(Return());
184         auto ret = service->AppendBundlesRestoreSession(UniqueFd(-1), {}, {}, RESTORE_DATA_WAIT_SEND, 0);
185         EXPECT_EQ(ret, BError(BError::Codes::EXT_THROW_EXCEPTION).GetCode());
186 
__anon410060db0902() 187         EXPECT_CALL(*sessionMock, IncreaseSessionCnt(_)).WillOnce(Invoke([]() {
188             throw "未知错误";
189         }));
190         EXPECT_CALL(*sessionMock, DecreaseSessionCnt(_)).WillOnce(Return());
191         ret = service->AppendBundlesRestoreSession(UniqueFd(-1), {}, {}, RESTORE_DATA_WAIT_SEND, 0);
192         EXPECT_EQ(ret, EPERM);
193     } catch (...) {
194         EXPECT_TRUE(false);
195         GTEST_LOG_(INFO) << "ServiceThrowTest-an exception occurred by AppendBundlesRestoreSession.";
196     }
197     GTEST_LOG_(INFO) << "ServiceThrowTest-end SUB_Service_throw_AppendBundlesRestoreSession_0100";
198 }
199 
200 /**
201  * @tc.number: SUB_Service_throw_AppendBundlesRestoreSession_0200
202  * @tc.name: SUB_Service_throw_AppendBundlesRestoreSession_0200
203  * @tc.desc: 测试 AppendBundlesRestoreSession 接口的 catch 分支
204  * @tc.size: MEDIUM
205  * @tc.type: FUNC
206  * @tc.level Level 1
207  * @tc.require: issuesIAC04T
208  */
209 HWTEST_F(ServiceThrowTest, SUB_Service_throw_AppendBundlesRestoreSession_0200, testing::ext::TestSize.Level1)
210 {
211     GTEST_LOG_(INFO) << "ServiceThrowTest-begin SUB_Service_throw_AppendBundlesRestoreSession_0200";
212     try {
213         EXPECT_NE(service, nullptr);
__anon410060db0a02() 214         EXPECT_CALL(*sessionMock, IncreaseSessionCnt(_)).WillOnce(Invoke([]() {
215             throw BError(BError::Codes::EXT_THROW_EXCEPTION);
216         }));
217         EXPECT_CALL(*sessionMock, DecreaseSessionCnt(_)).WillOnce(Return());
218         auto ret = service->AppendBundlesRestoreSession(UniqueFd(-1), {}, RESTORE_DATA_WAIT_SEND, 0);
219         EXPECT_EQ(ret, BError(BError::Codes::EXT_THROW_EXCEPTION).GetCode());
220 
__anon410060db0b02() 221         EXPECT_CALL(*sessionMock, IncreaseSessionCnt(_)).WillOnce(Invoke([]() {
222             throw "未知错误";
223         }));
224         EXPECT_CALL(*sessionMock, DecreaseSessionCnt(_)).WillOnce(Return());
225         ret = service->AppendBundlesRestoreSession(UniqueFd(-1), {}, RESTORE_DATA_WAIT_SEND, 0);
226         EXPECT_EQ(ret, EPERM);
227     } catch (...) {
228         EXPECT_TRUE(false);
229         GTEST_LOG_(INFO) << "ServiceThrowTest-an exception occurred by AppendBundlesRestoreSession.";
230     }
231     GTEST_LOG_(INFO) << "ServiceThrowTest-end SUB_Service_throw_AppendBundlesRestoreSession_0200";
232 }
233 
234 /**
235  * @tc.number: SUB_Service_throw_AppendBundlesBackupSession_0100
236  * @tc.name: SUB_Service_throw_AppendBundlesBackupSession_0100
237  * @tc.desc: 测试 AppendBundlesBackupSession 接口的 catch 分支
238  * @tc.size: MEDIUM
239  * @tc.type: FUNC
240  * @tc.level Level 1
241  * @tc.require: issuesIAC04T
242  */
243 HWTEST_F(ServiceThrowTest, SUB_Service_throw_AppendBundlesBackupSession_0100, testing::ext::TestSize.Level1)
244 {
245     GTEST_LOG_(INFO) << "ServiceThrowTest-begin SUB_Service_throw_AppendBundlesBackupSession_0100";
246     try {
247         EXPECT_NE(service, nullptr);
__anon410060db0c02() 248         EXPECT_CALL(*sessionMock, IncreaseSessionCnt(_)).WillOnce(Invoke([]() {
249             throw BError(BError::Codes::EXT_THROW_EXCEPTION);
250         }));
251         EXPECT_CALL(*sessionMock, DecreaseSessionCnt(_)).WillOnce(Return());
252         auto ret = service->AppendBundlesBackupSession({});
253         EXPECT_EQ(ret, BError(BError::Codes::EXT_THROW_EXCEPTION).GetCode());
254 
__anon410060db0d02() 255         EXPECT_CALL(*sessionMock, IncreaseSessionCnt(_)).WillOnce(Invoke([]() {
256             throw runtime_error("运行时错误");
257         }));
258         EXPECT_CALL(*sessionMock, DecreaseSessionCnt(_)).WillOnce(Return());
259         ret = service->AppendBundlesBackupSession({});
260         EXPECT_EQ(ret, EPERM);
261 
__anon410060db0e02() 262         EXPECT_CALL(*sessionMock, IncreaseSessionCnt(_)).WillOnce(Invoke([]() {
263             throw "未知错误";
264         }));
265         EXPECT_CALL(*sessionMock, DecreaseSessionCnt(_)).WillOnce(Return());
266         ret = service->AppendBundlesBackupSession({});
267         EXPECT_EQ(ret, EPERM);
268     } catch (...) {
269         EXPECT_TRUE(false);
270         GTEST_LOG_(INFO) << "ServiceThrowTest-an exception occurred by AppendBundlesBackupSession.";
271     }
272     GTEST_LOG_(INFO) << "ServiceThrowTest-end SUB_Service_throw_AppendBundlesBackupSession_0100";
273 }
274 
275 /**
276  * @tc.number: SUB_Service_throw_AppendBundlesDetailsBackupSession_0100
277  * @tc.name: SUB_Service_throw_AppendBundlesDetailsBackupSession_0100
278  * @tc.desc: 测试 AppendBundlesDetailsBackupSession 接口的 catch 分支
279  * @tc.size: MEDIUM
280  * @tc.type: FUNC
281  * @tc.level Level 1
282  * @tc.require: issuesIAC04T
283  */
284 HWTEST_F(ServiceThrowTest, SUB_Service_throw_AppendBundlesDetailsBackupSession_0100, testing::ext::TestSize.Level1)
285 {
286     GTEST_LOG_(INFO) << "ServiceThrowTest-begin SUB_Service_throw_AppendBundlesDetailsBackupSession_0100";
287     try {
288         EXPECT_NE(service, nullptr);
__anon410060db0f02() 289         EXPECT_CALL(*sessionMock, IncreaseSessionCnt(_)).WillOnce(Invoke([]() {
290             throw BError(BError::Codes::EXT_THROW_EXCEPTION);
291         }));
292         EXPECT_CALL(*sessionMock, DecreaseSessionCnt(_)).WillOnce(Return());
293         auto ret = service->AppendBundlesDetailsBackupSession({}, {});
294         EXPECT_EQ(ret, BError(BError::Codes::EXT_THROW_EXCEPTION).GetCode());
295 
__anon410060db1002() 296         EXPECT_CALL(*sessionMock, IncreaseSessionCnt(_)).WillOnce(Invoke([]() {
297             throw runtime_error("运行时错误");
298         }));
299         EXPECT_CALL(*sessionMock, DecreaseSessionCnt(_)).WillOnce(Return());
300         ret = service->AppendBundlesDetailsBackupSession({}, {});
301         EXPECT_EQ(ret, EPERM);
302 
__anon410060db1102() 303         EXPECT_CALL(*sessionMock, IncreaseSessionCnt(_)).WillOnce(Invoke([]() {
304             throw "未知错误";
305         }));
306         EXPECT_CALL(*sessionMock, DecreaseSessionCnt(_)).WillOnce(Return());
307         ret = service->AppendBundlesDetailsBackupSession({}, {});
308         EXPECT_EQ(ret, EPERM);
309     } catch (...) {
310         EXPECT_TRUE(false);
311         GTEST_LOG_(INFO) << "ServiceThrowTest-an exception occurred by AppendBundlesDetailsBackupSession.";
312     }
313     GTEST_LOG_(INFO) << "ServiceThrowTest-end SUB_Service_throw_AppendBundlesDetailsBackupSession_0100";
314 }
315 
316 /**
317  * @tc.number: SUB_Service_throw_PublishFile_0100
318  * @tc.name: SUB_Service_throw_PublishFile_0100
319  * @tc.desc: 测试 PublishFile 接口的 catch 分支
320  * @tc.size: MEDIUM
321  * @tc.type: FUNC
322  * @tc.level Level 1
323  * @tc.require: issuesIAC04T
324  */
325 HWTEST_F(ServiceThrowTest, SUB_Service_throw_PublishFile_0100, testing::ext::TestSize.Level1)
326 {
327     GTEST_LOG_(INFO) << "ServiceThrowTest-begin SUB_Service_throw_PublishFile_0100";
328     try {
329         EXPECT_NE(service, nullptr);
330         BFileInfo fileInfo;
__anon410060db1202() 331         EXPECT_CALL(*sessionMock, VerifyCallerAndScenario(_, _)).WillOnce(Invoke([]() {
332             throw BError(BError::Codes::EXT_THROW_EXCEPTION);
333         }));
334         auto ret = service->PublishFile(fileInfo);
335         EXPECT_EQ(ret, BError(BError::Codes::EXT_THROW_EXCEPTION).GetCode());
336 
__anon410060db1302() 337         EXPECT_CALL(*sessionMock, VerifyCallerAndScenario(_, _)).WillOnce(Invoke([]() {
338             throw runtime_error("运行时错误");
339         }));
340         ret = service->PublishFile(fileInfo);
341         EXPECT_EQ(ret, EPERM);
342 
__anon410060db1402() 343         EXPECT_CALL(*sessionMock, VerifyCallerAndScenario(_, _)).WillOnce(Invoke([]() {
344             throw "未知错误";
345         }));
346         ret = service->PublishFile(fileInfo);
347         EXPECT_EQ(ret, EPERM);
348     } catch (...) {
349         EXPECT_TRUE(false);
350         GTEST_LOG_(INFO) << "ServiceThrowTest-an exception occurred by PublishFile.";
351     }
352     GTEST_LOG_(INFO) << "ServiceThrowTest-end SUB_Service_throw_PublishFile_0100";
353 }
354 
355 /**
356  * @tc.number: SUB_Service_throw_AppFileReady_0100
357  * @tc.name: SUB_Service_throw_AppFileReady_0100
358  * @tc.desc: 测试 AppFileReady 接口的 catch 分支
359  * @tc.size: MEDIUM
360  * @tc.type: FUNC
361  * @tc.level Level 1
362  * @tc.require: issuesIAC04T
363  */
364 HWTEST_F(ServiceThrowTest, SUB_Service_throw_AppFileReady_0100, testing::ext::TestSize.Level1)
365 {
366     GTEST_LOG_(INFO) << "ServiceThrowTest-begin SUB_Service_throw_AppFileReady_0100";
367     try {
368         EXPECT_NE(service, nullptr);
369         string fileName;
__anon410060db1502() 370         EXPECT_CALL(*sessionMock, VerifyBundleName(_)).WillOnce(Invoke([]() {
371             throw BError(BError::Codes::EXT_THROW_EXCEPTION);
372         }));
373         auto ret = service->AppFileReady(fileName, UniqueFd(-1), 0);
374         EXPECT_EQ(ret, BError(BError::Codes::EXT_THROW_EXCEPTION).GetCode());
375 
__anon410060db1602() 376         EXPECT_CALL(*sessionMock, VerifyBundleName(_)).WillOnce(Invoke([]() {
377             throw runtime_error("运行时错误");
378         }));
379         ret = service->AppFileReady(fileName, UniqueFd(-1), 0);
380         EXPECT_EQ(ret, EPERM);
381 
__anon410060db1702() 382         EXPECT_CALL(*sessionMock, VerifyBundleName(_)).WillOnce(Invoke([]() {
383             throw "未知错误";
384         }));
385         ret = service->AppFileReady(fileName, UniqueFd(-1), 0);
386         EXPECT_EQ(ret, EPERM);
387     } catch (...) {
388         EXPECT_TRUE(false);
389         GTEST_LOG_(INFO) << "ServiceThrowTest-an exception occurred by AppFileReady.";
390     }
391     GTEST_LOG_(INFO) << "ServiceThrowTest-end SUB_Service_throw_AppFileReady_0100";
392 }
393 
394 /**
395  * @tc.number: SUB_Service_throw_AppDone_0100
396  * @tc.name: SUB_Service_throw_AppDone_0100
397  * @tc.desc: 测试 AppDone 接口的 catch 分支
398  * @tc.size: MEDIUM
399  * @tc.type: FUNC
400  * @tc.level Level 1
401  * @tc.require: issuesIAC04T
402  */
403 HWTEST_F(ServiceThrowTest, SUB_Service_throw_AppDone_0100, testing::ext::TestSize.Level1)
404 {
405     GTEST_LOG_(INFO) << "ServiceThrowTest-begin SUB_Service_throw_AppDone_0100";
406     try {
407         EXPECT_NE(service, nullptr);
__anon410060db1802() 408         EXPECT_CALL(*sessionMock, VerifyBundleName(_)).WillOnce(Invoke([]() {
409             throw BError(BError::Codes::EXT_THROW_EXCEPTION);
410         }));
411         auto ret = service->AppDone(0);
412         EXPECT_EQ(ret, BError(BError::Codes::EXT_THROW_EXCEPTION).GetCode());
413 
__anon410060db1902() 414         EXPECT_CALL(*sessionMock, VerifyBundleName(_)).WillOnce(Invoke([]() {
415             throw runtime_error("运行时错误");
416         }));
417         ret = service->AppDone(0);
418         EXPECT_EQ(ret, EPERM);
419 
__anon410060db1a02() 420         EXPECT_CALL(*sessionMock, VerifyBundleName(_)).WillOnce(Invoke([]() {
421             throw "未知错误";
422         }));
423         ret = service->AppDone(0);
424         EXPECT_EQ(ret, EPERM);
425     } catch (...) {
426         EXPECT_TRUE(false);
427         GTEST_LOG_(INFO) << "ServiceThrowTest-an exception occurred by AppDone.";
428     }
429     GTEST_LOG_(INFO) << "ServiceThrowTest-end SUB_Service_throw_AppDone_0100";
430 }
431 
432 /**
433  * @tc.number: SUB_Service_throw_LaunchBackupExtension_0100
434  * @tc.name: SUB_Service_throw_LaunchBackupExtension_0100
435  * @tc.desc: 测试 LaunchBackupExtension 接口的 catch 分支
436  * @tc.size: MEDIUM
437  * @tc.type: FUNC
438  * @tc.level Level 1
439  * @tc.require: issuesIAC04T
440  */
441 HWTEST_F(ServiceThrowTest, SUB_Service_throw_LaunchBackupExtension_0100, testing::ext::TestSize.Level1)
442 {
443     GTEST_LOG_(INFO) << "ServiceThrowTest-begin SUB_Service_throw_LaunchBackupExtension_0100";
444     try {
445         EXPECT_NE(service, nullptr);
446         BundleName bundleName;
__anon410060db1b02() 447         EXPECT_CALL(*sessionMock, GetScenario()).WillOnce(Invoke([]() {
448             throw BError(BError::Codes::EXT_THROW_EXCEPTION);
449             return IServiceReverse::Scenario::UNDEFINED;
450         }));
451         auto ret = service->LaunchBackupExtension(bundleName);
452         EXPECT_EQ(ret, BError(BError::Codes::EXT_THROW_EXCEPTION).GetCode());
453 
__anon410060db1c02() 454         EXPECT_CALL(*sessionMock, GetScenario()).WillOnce(Invoke([]() {
455             throw runtime_error("运行时错误");
456             return IServiceReverse::Scenario::UNDEFINED;
457         }));
458         ret = service->LaunchBackupExtension(bundleName);
459         EXPECT_EQ(ret, EPERM);
460 
__anon410060db1d02() 461         EXPECT_CALL(*sessionMock, GetScenario()).WillOnce(Invoke([]() {
462             throw "未知错误";
463             return IServiceReverse::Scenario::UNDEFINED;
464         }));
465         ret = service->LaunchBackupExtension(bundleName);
466         EXPECT_EQ(ret, EPERM);
467     } catch (...) {
468         EXPECT_TRUE(false);
469         GTEST_LOG_(INFO) << "ServiceThrowTest-an exception occurred by LaunchBackupExtension.";
470     }
471     GTEST_LOG_(INFO) << "ServiceThrowTest-end SUB_Service_throw_LaunchBackupExtension_0100";
472 }
473 
474 /**
475  * @tc.number: SUB_Service_throw_GetFileHandle_0100
476  * @tc.name: SUB_Service_throw_GetFileHandle_0100
477  * @tc.desc: 测试 GetFileHandle 接口的 catch 分支
478  * @tc.size: MEDIUM
479  * @tc.type: FUNC
480  * @tc.level Level 1
481  * @tc.require: issuesIAC04T
482  */
483 HWTEST_F(ServiceThrowTest, SUB_Service_throw_GetFileHandle_0100, testing::ext::TestSize.Level1)
484 {
485     GTEST_LOG_(INFO) << "ServiceThrowTest-begin SUB_Service_throw_GetFileHandle_0100";
486     try {
487         EXPECT_NE(service, nullptr);
488         string bundleName;
489         string fileName;
__anon410060db1e02() 490         EXPECT_CALL(*sessionMock, VerifyCallerAndScenario(_, _)).WillOnce(Invoke([]() {
491             throw BError(BError::Codes::EXT_THROW_EXCEPTION);
492         }));
493         auto ret = service->GetFileHandle(bundleName, fileName);
494         EXPECT_EQ(ret, BError(BError::Codes::EXT_THROW_EXCEPTION).GetCode());
495 
__anon410060db1f02() 496         EXPECT_CALL(*sessionMock, VerifyCallerAndScenario(_, _)).WillOnce(Invoke([]() {
497             throw runtime_error("运行时错误");
498         }));
499         ret = service->GetFileHandle(bundleName, fileName);
500         EXPECT_EQ(ret, EPERM);
501 
__anon410060db2002() 502         EXPECT_CALL(*sessionMock, VerifyCallerAndScenario(_, _)).WillOnce(Invoke([]() {
503             throw "未知错误";
504         }));
505         ret = service->GetFileHandle(bundleName, fileName);
506         EXPECT_EQ(ret, EPERM);
507     } catch (...) {
508         EXPECT_TRUE(false);
509         GTEST_LOG_(INFO) << "ServiceThrowTest-an exception occurred by GetFileHandle.";
510     }
511     GTEST_LOG_(INFO) << "ServiceThrowTest-end SUB_Service_throw_GetFileHandle_0100";
512 }
513 
514 /**
515  * @tc.number: SUB_Service_throw_OnBackupExtensionDied_0100
516  * @tc.name: SUB_Service_throw_OnBackupExtensionDied_0100
517  * @tc.desc: 测试 OnBackupExtensionDied 接口的 catch 分支
518  * @tc.size: MEDIUM
519  * @tc.type: FUNC
520  * @tc.level Level 1
521  * @tc.require: issuesIAC04T
522  */
523 HWTEST_F(ServiceThrowTest, SUB_Service_throw_OnBackupExtensionDied_0100, testing::ext::TestSize.Level1)
524 {
525     GTEST_LOG_(INFO) << "ServiceThrowTest-begin SUB_Service_throw_OnBackupExtensionDied_0100";
526     try {
527         EXPECT_NE(service, nullptr);
528         string bundleName;
529         EXPECT_CALL(*sessionMock, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED))
530             .WillOnce(Return(IServiceReverse::Scenario::UNDEFINED))
__anon410060db2102() 531             .WillOnce(Invoke([]() {
532             throw "未知错误";
533             return IServiceReverse::Scenario::UNDEFINED;
534         }));
__anon410060db2202() 535         EXPECT_CALL(*sessionMock, VerifyBundleName(_)).WillOnce(Invoke([]() {
536             throw BError(BError::Codes::EXT_THROW_EXCEPTION);
537         }));
__anon410060db2302() 538         EXPECT_CALL(*sessionMock, StopFwkTimer(_)).WillOnce(Invoke([]() {
539             throw BError(BError::Codes::EXT_THROW_EXCEPTION);
540             return true;
541         }));
__anon410060db2402() 542         EXPECT_CALL(*sessionMock, RemoveExtInfo(_)).WillOnce(Invoke([]() {
543             throw BError(BError::Codes::EXT_THROW_EXCEPTION);
544         }));
545         EXPECT_CALL(*sessionMock, IsOnAllBundlesFinished()).WillOnce(Return(false));
546         service->OnBackupExtensionDied("bundleName");
547         EXPECT_TRUE(true);
548     } catch (...) {
549         EXPECT_TRUE(false);
550         GTEST_LOG_(INFO) << "ServiceThrowTest-an exception occurred by OnBackupExtensionDied.";
551     }
552     GTEST_LOG_(INFO) << "ServiceThrowTest-end SUB_Service_throw_OnBackupExtensionDied_0100";
553 }
554 
555 /**
556  * @tc.number: SUB_Service_throw_ExtStart_0100
557  * @tc.name: SUB_Service_throw_ExtStart_0100
558  * @tc.desc: 测试 ExtStart 接口的 catch 分支
559  * @tc.size: MEDIUM
560  * @tc.type: FUNC
561  * @tc.level Level 1
562  * @tc.require: issuesIAC04T
563  */
564 HWTEST_F(ServiceThrowTest, SUB_Service_throw_ExtStart_0100, testing::ext::TestSize.Level1)
565 {
566     GTEST_LOG_(INFO) << "ServiceThrowTest-begin SUB_Service_throw_ExtStart_0100";
567     try {
568         EXPECT_NE(service, nullptr);
569         string bundleName;
__anon410060db2502() 570         EXPECT_CALL(*sessionMock, GetScenario()).WillOnce(Invoke([]() {
571             throw BError(BError::Codes::EXT_THROW_EXCEPTION);
572             return IServiceReverse::Scenario::UNDEFINED;
573         })).WillOnce(Invoke([]() {
574             throw BError(BError::Codes::EXT_THROW_EXCEPTION);
575             return IServiceReverse::Scenario::UNDEFINED;
576         }));
__anon410060db2702() 577         EXPECT_CALL(*sessionMock, RemoveExtInfo(_)).WillOnce(Invoke([]() {
578             throw BError(BError::Codes::EXT_THROW_EXCEPTION);
579         }));
580         EXPECT_CALL(*sessionMock, IsOnAllBundlesFinished()).WillOnce(Return(false));
581         service->ExtStart(bundleName);
582         EXPECT_TRUE(true);
583     } catch (...) {
584         EXPECT_TRUE(false);
585         GTEST_LOG_(INFO) << "ServiceThrowTest-an exception occurred by ExtStart.";
586     }
587     GTEST_LOG_(INFO) << "ServiceThrowTest-end SUB_Service_throw_ExtStart_0100";
588 }
589 
590 /**
591  * @tc.number: SUB_Service_throw_ExtConnectFailed_0100
592  * @tc.name: SUB_Service_throw_ExtConnectFailed_0100
593  * @tc.desc: 测试 ExtConnectFailed 接口的 catch 分支
594  * @tc.size: MEDIUM
595  * @tc.type: FUNC
596  * @tc.level Level 1
597  * @tc.require: issuesIAC04T
598  */
599 HWTEST_F(ServiceThrowTest, SUB_Service_throw_ExtConnectFailed_0100, testing::ext::TestSize.Level1)
600 {
601     GTEST_LOG_(INFO) << "ServiceThrowTest-begin SUB_Service_throw_ExtConnectFailed_0100";
602     try {
603         EXPECT_NE(service, nullptr);
604         BundleName bundleName;
__anon410060db2802() 605         EXPECT_CALL(*sessionMock, GetScenario()).WillOnce(Invoke([]() {
606             throw BError(BError::Codes::EXT_THROW_EXCEPTION);
607             return IServiceReverse::Scenario::UNDEFINED;
608         })).WillOnce(Invoke([]() {
609             throw BError(BError::Codes::EXT_THROW_EXCEPTION);
610             return IServiceReverse::Scenario::UNDEFINED;
611         }));
612         service->ExtConnectFailed(bundleName, 0);
613         EXPECT_TRUE(true);
614 
__anon410060db2a02() 615         EXPECT_CALL(*sessionMock, GetScenario()).WillOnce(Invoke([]() {
616             throw runtime_error("运行时错误");
617             return IServiceReverse::Scenario::UNDEFINED;
618         })).WillOnce(Invoke([]() {
619             throw runtime_error("运行时错误");
620             return IServiceReverse::Scenario::UNDEFINED;
621         }));
622         service->ExtConnectFailed(bundleName, 0);
623         EXPECT_TRUE(true);
624 
__anon410060db2c02() 625         EXPECT_CALL(*sessionMock, GetScenario()).WillOnce(Invoke([]() {
626             throw "未知错误";
627             return IServiceReverse::Scenario::UNDEFINED;
628         })).WillOnce(Invoke([]() {
629             throw "未知错误";
630             return IServiceReverse::Scenario::UNDEFINED;
631         }));
632         service->ExtConnectFailed(bundleName, 0);
633         EXPECT_TRUE(true);
634     } catch (...) {
635         EXPECT_TRUE(false);
636         GTEST_LOG_(INFO) << "ServiceThrowTest-an exception occurred by ExtConnectFailed.";
637     }
638     GTEST_LOG_(INFO) << "ServiceThrowTest-end SUB_Service_throw_ExtConnectFailed_0100";
639 }
640 
641 /**
642  * @tc.number: SUB_Service_throw_NoticeClientFinish_0100
643  * @tc.name: SUB_Service_throw_NoticeClientFinish_0100
644  * @tc.desc: 测试 NoticeClientFinish 接口的 catch 分支
645  * @tc.size: MEDIUM
646  * @tc.type: FUNC
647  * @tc.level Level 1
648  * @tc.require: issuesIAC04T
649  */
650 HWTEST_F(ServiceThrowTest, SUB_Service_throw_NoticeClientFinish_0100, testing::ext::TestSize.Level1)
651 {
652     GTEST_LOG_(INFO) << "ServiceThrowTest-begin SUB_Service_throw_NoticeClientFinish_0100";
653     try {
654         EXPECT_NE(service, nullptr);
655         string bundleName;
656         ErrCode errCode = 0;
__anon410060db2e02() 657         EXPECT_CALL(*sessionMock, GetScenario()).WillOnce(Invoke([]() {
658             throw BError(BError::Codes::EXT_THROW_EXCEPTION);
659             return IServiceReverse::Scenario::UNDEFINED;
660         }));
661         EXPECT_CALL(*sessionMock, IsOnAllBundlesFinished()).WillOnce(Return(false));
662         service->NoticeClientFinish(bundleName, errCode);
663         EXPECT_TRUE(true);
664     } catch (...) {
665         EXPECT_TRUE(false);
666         GTEST_LOG_(INFO) << "ServiceThrowTest-an exception occurred by NoticeClientFinish.";
667     }
668     GTEST_LOG_(INFO) << "ServiceThrowTest-end SUB_Service_throw_NoticeClientFinish_0100";
669 }
670 
671 /**
672  * @tc.number: SUB_Service_throw_ClearSessionAndSchedInfo_0100
673  * @tc.name: SUB_Service_throw_ClearSessionAndSchedInfo_0100
674  * @tc.desc: 测试 ClearSessionAndSchedInfo 接口的 catch 分支
675  * @tc.size: MEDIUM
676  * @tc.type: FUNC
677  * @tc.level Level 1
678  * @tc.require: issuesIAC04T
679  */
680 HWTEST_F(ServiceThrowTest, SUB_Service_throw_ClearSessionAndSchedInfo_0100, testing::ext::TestSize.Level1)
681 {
682     GTEST_LOG_(INFO) << "ServiceThrowTest-begin SUB_Service_throw_ClearSessionAndSchedInfo_0100";
683     try {
684         EXPECT_NE(service, nullptr);
685         BundleName bundleName;
__anon410060db2f02() 686         EXPECT_CALL(*sessionMock, RemoveExtInfo(_)).WillOnce(Invoke([]() {
687             throw BError(BError::Codes::EXT_THROW_EXCEPTION);
688         }));
689         service->ClearSessionAndSchedInfo(bundleName);
690         EXPECT_TRUE(true);
691 
__anon410060db3002() 692         EXPECT_CALL(*sessionMock, RemoveExtInfo(_)).WillOnce(Invoke([]() {
693             throw runtime_error("运行时错误");
694         }));
695         service->ClearSessionAndSchedInfo(bundleName);
696         EXPECT_TRUE(true);
697 
__anon410060db3102() 698         EXPECT_CALL(*sessionMock, RemoveExtInfo(_)).WillOnce(Invoke([]() {
699             throw "未知错误";
700         }));
701         service->ClearSessionAndSchedInfo(bundleName);
702         EXPECT_TRUE(true);
703     } catch (...) {
704         EXPECT_TRUE(false);
705         GTEST_LOG_(INFO) << "ServiceThrowTest-an exception occurred by ClearSessionAndSchedInfo.";
706     }
707     GTEST_LOG_(INFO) << "ServiceThrowTest-end SUB_Service_throw_ClearSessionAndSchedInfo_0100";
708 }
709 
710 /**
711  * @tc.number: SUB_Service_throw_GetBackupInfo_0100
712  * @tc.name: SUB_Service_throw_GetBackupInfo_0100
713  * @tc.desc: 测试 GetBackupInfo 接口的 catch 分支
714  * @tc.size: MEDIUM
715  * @tc.type: FUNC
716  * @tc.level Level 1
717  * @tc.require: issuesIAC04T
718  */
719 HWTEST_F(ServiceThrowTest, SUB_Service_throw_GetBackupInfo_0100, testing::ext::TestSize.Level1)
720 {
721     GTEST_LOG_(INFO) << "ServiceThrowTest-begin SUB_Service_throw_GetBackupInfo_0100";
722     try {
723         EXPECT_NE(service, nullptr);
724         BundleName bundleName;
725         string result;
__anon410060db3202() 726         EXPECT_CALL(*sessionMock, IncreaseSessionCnt(_)).WillOnce(Invoke([]() {
727             throw "未知错误";
728         }));
729         EXPECT_CALL(*sessionMock, DecreaseSessionCnt(_)).WillOnce(Return());
730         auto ret = service->GetBackupInfo(bundleName, result);
731         EXPECT_EQ(ret, EPERM);
732     } catch (...) {
733         EXPECT_TRUE(false);
734         GTEST_LOG_(INFO) << "ServiceThrowTest-an exception occurred by GetBackupInfo.";
735     }
736     GTEST_LOG_(INFO) << "ServiceThrowTest-end SUB_Service_throw_GetBackupInfo_0100";
737 }
738 
739 /**
740  * @tc.number: SUB_Service_throw_UpdateTimer_0100
741  * @tc.name: SUB_Service_throw_UpdateTimer_0100
742  * @tc.desc: 测试 UpdateTimer 接口的 catch 分支
743  * @tc.size: MEDIUM
744  * @tc.type: FUNC
745  * @tc.level Level 1
746  * @tc.require: issuesIAC04T
747  */
748 HWTEST_F(ServiceThrowTest, SUB_Service_throw_UpdateTimer_0100, testing::ext::TestSize.Level1)
749 {
750     GTEST_LOG_(INFO) << "ServiceThrowTest-begin SUB_Service_throw_UpdateTimer_0100";
751     try {
752         EXPECT_NE(service, nullptr);
753         BundleName bundleName;
754         bool result = false;
__anon410060db3302() 755         EXPECT_CALL(*sessionMock, IncreaseSessionCnt(_)).WillOnce(Invoke([]() {
756             throw "未知错误";
757         }));
758         EXPECT_CALL(*sessionMock, DecreaseSessionCnt(_)).WillOnce(Return());
759         auto ret = service->UpdateTimer(bundleName, 0, result);
760         EXPECT_EQ(ret, EPERM);
761     } catch (...) {
762         EXPECT_TRUE(false);
763         GTEST_LOG_(INFO) << "ServiceThrowTest-an exception occurred by UpdateTimer.";
764     }
765     GTEST_LOG_(INFO) << "ServiceThrowTest-end SUB_Service_throw_UpdateTimer_0100";
766 }
767 
768 /**
769  * @tc.number: SUB_Service_throw_SADone_0100
770  * @tc.name: SUB_Service_throw_SADone_0100
771  * @tc.desc: 测试 SADone 接口的 catch 分支
772  * @tc.size: MEDIUM
773  * @tc.type: FUNC
774  * @tc.level Level 1
775  * @tc.require: issuesIAC04T
776  */
777 HWTEST_F(ServiceThrowTest, SUB_Service_throw_SADone_0100, testing::ext::TestSize.Level1)
778 {
779     GTEST_LOG_(INFO) << "ServiceThrowTest-begin SUB_Service_throw_SADone_0100";
780     try {
781         EXPECT_NE(service, nullptr);
782         ErrCode errCode = 0;
783         string bundleName;
__anon410060db3402() 784         EXPECT_CALL(*sessionMock, OnBundleFileReady(_, _)).WillOnce(Invoke([]() {
785             throw BError(BError::Codes::EXT_THROW_EXCEPTION);
786             return false;
787         }));
788         EXPECT_CALL(*sessionMock, IsOnAllBundlesFinished()).WillOnce(Return(false));
789         auto ret = service->SADone(errCode, bundleName);
790         EXPECT_EQ(ret, BError(BError::Codes::EXT_THROW_EXCEPTION).GetCode());
791 
__anon410060db3502() 792         EXPECT_CALL(*sessionMock, OnBundleFileReady(_, _)).WillOnce(Invoke([]() {
793             throw runtime_error("运行时错误");
794             return false;
795         }));
796         EXPECT_CALL(*sessionMock, IsOnAllBundlesFinished()).WillOnce(Return(false));
797         ret = service->SADone(errCode, bundleName);
798         EXPECT_EQ(ret, EPERM);
799 
__anon410060db3602() 800         EXPECT_CALL(*sessionMock, OnBundleFileReady(_, _)).WillOnce(Invoke([]() {
801             throw "未知错误";
802             return false;
803         }));
804         EXPECT_CALL(*sessionMock, IsOnAllBundlesFinished()).WillOnce(Return(false));
805         ret = service->SADone(errCode, bundleName);
806         EXPECT_EQ(ret, EPERM);
807     } catch (...) {
808         EXPECT_TRUE(false);
809         GTEST_LOG_(INFO) << "ServiceThrowTest-an exception occurred by SADone.";
810     }
811     GTEST_LOG_(INFO) << "ServiceThrowTest-end SUB_Service_throw_SADone_0100";
812 }
813 
814 /**
815  * @tc.number: SUB_Service_throw_GetLocalCapabilitiesIncremental_0100
816  * @tc.name: SUB_Service_throw_GetLocalCapabilitiesIncremental_0100
817  * @tc.desc: 测试 GetLocalCapabilitiesIncremental 接口的 catch 分支
818  * @tc.size: MEDIUM
819  * @tc.type: FUNC
820  * @tc.level Level 1
821  * @tc.require: issuesIAC04T
822  */
823 HWTEST_F(ServiceThrowTest, SUB_Service_throw_GetLocalCapabilitiesIncremental_0100, testing::ext::TestSize.Level1)
824 {
825     GTEST_LOG_(INFO) << "ServiceThrowTest-begin SUB_Service_throw_GetLocalCapabilitiesIncremental_0100";
826     try {
827         EXPECT_NE(service, nullptr);
828         vector<BIncrementalData> bundleNames;
__anon410060db3702() 829         EXPECT_CALL(*sessionMock, IncreaseSessionCnt(_)).WillOnce(Invoke([]() {
830             throw BError(BError::Codes::EXT_THROW_EXCEPTION);
831         }));
832         EXPECT_CALL(*sessionMock, DecreaseSessionCnt(_)).WillOnce(Return());
833         auto ret = service->GetLocalCapabilitiesIncremental(bundleNames);
834         EXPECT_EQ(-ret, BError(BError::Codes::EXT_THROW_EXCEPTION).GetCode());
835 
__anon410060db3802() 836         EXPECT_CALL(*sessionMock, IncreaseSessionCnt(_)).WillOnce(Invoke([]() {
837             throw runtime_error("运行时错误");
838         }));
839         EXPECT_CALL(*sessionMock, DecreaseSessionCnt(_)).WillOnce(Return());
840         ret = service->GetLocalCapabilitiesIncremental(bundleNames);
841         EXPECT_EQ(-ret, EPERM);
842 
__anon410060db3902() 843         EXPECT_CALL(*sessionMock, IncreaseSessionCnt(_)).WillOnce(Invoke([]() {
844             throw "未知错误";
845         }));
846         EXPECT_CALL(*sessionMock, DecreaseSessionCnt(_)).WillOnce(Return());
847         ret = service->GetLocalCapabilitiesIncremental(bundleNames);
848         EXPECT_EQ(-ret, EPERM);
849     } catch (...) {
850         EXPECT_TRUE(false);
851         GTEST_LOG_(INFO) << "ServiceThrowTest-an exception occurred by GetLocalCapabilitiesIncremental.";
852     }
853     GTEST_LOG_(INFO) << "ServiceThrowTest-end SUB_Service_throw_GetLocalCapabilitiesIncremental_0100";
854 }
855 
856 /**
857  * @tc.number: SUB_Service_throw_GetAppLocalListAndDoIncrementalBackup_0100
858  * @tc.name: SUB_Service_throw_GetAppLocalListAndDoIncrementalBackup_0100
859  * @tc.desc: 测试 GetAppLocalListAndDoIncrementalBackup 接口的 catch 分支
860  * @tc.size: MEDIUM
861  * @tc.type: FUNC
862  * @tc.level Level 1
863  * @tc.require: issuesIAC04T
864  */
865 HWTEST_F(ServiceThrowTest, SUB_Service_throw_GetAppLocalListAndDoIncrementalBackup_0100, testing::ext::TestSize.Level1)
866 {
867     GTEST_LOG_(INFO) << "ServiceThrowTest-begin SUB_Service_throw_GetAppLocalListAndDoIncrementalBackup_0100";
868     try {
869         EXPECT_NE(service, nullptr);
__anon410060db3a02() 870         EXPECT_CALL(*sessionMock, IncreaseSessionCnt(_)).WillOnce(Invoke([]() {
871             throw BError(BError::Codes::EXT_THROW_EXCEPTION);
872         }));
873         EXPECT_CALL(*sessionMock, DecreaseSessionCnt(_)).WillOnce(Return());
874         auto ret = service->GetAppLocalListAndDoIncrementalBackup();
875         EXPECT_EQ(ret, BError(BError::Codes::EXT_THROW_EXCEPTION).GetCode());
876 
__anon410060db3b02() 877         EXPECT_CALL(*sessionMock, IncreaseSessionCnt(_)).WillOnce(Invoke([]() {
878             throw runtime_error("运行时错误");
879         }));
880         EXPECT_CALL(*sessionMock, DecreaseSessionCnt(_)).WillOnce(Return());
881         ret = service->GetAppLocalListAndDoIncrementalBackup();
882         EXPECT_EQ(ret, EPERM);
883 
__anon410060db3c02() 884         EXPECT_CALL(*sessionMock, IncreaseSessionCnt(_)).WillOnce(Invoke([]() {
885             throw "未知错误";
886         }));
887         EXPECT_CALL(*sessionMock, DecreaseSessionCnt(_)).WillOnce(Return());
888         ret = service->GetAppLocalListAndDoIncrementalBackup();
889         EXPECT_EQ(ret, EPERM);
890     } catch (...) {
891         EXPECT_TRUE(false);
892         GTEST_LOG_(INFO) << "ServiceThrowTest-an exception occurred by GetAppLocalListAndDoIncrementalBackup.";
893     }
894     GTEST_LOG_(INFO) << "ServiceThrowTest-end SUB_Service_throw_GetAppLocalListAndDoIncrementalBackup_0100";
895 }
896 
897 /**
898  * @tc.number: SUB_Service_throw_InitIncrementalBackupSession_0100
899  * @tc.name: SUB_Service_throw_InitIncrementalBackupSession_0100
900  * @tc.desc: 测试 InitIncrementalBackupSession 接口的 catch 分支
901  * @tc.size: MEDIUM
902  * @tc.type: FUNC
903  * @tc.level Level 1
904  * @tc.require: issuesIAC04T
905  */
906 HWTEST_F(ServiceThrowTest, SUB_Service_throw_InitIncrementalBackupSession_0100, testing::ext::TestSize.Level1)
907 {
908     GTEST_LOG_(INFO) << "ServiceThrowTest-begin SUB_Service_throw_InitIncrementalBackupSession_0100";
909     try {
910         EXPECT_NE(service, nullptr);
__anon410060db3d02() 911         EXPECT_CALL(*sessionMock, Active(_)).WillOnce(Invoke([]() {
912             throw BError(BError::Codes::EXT_THROW_EXCEPTION);
913             return 0;
914         }));
915         EXPECT_CALL(*sessionMock, Deactive(_, _)).WillOnce(Return());
916         EXPECT_CALL(*sessionMock, GetScenario()).WillOnce(Return(IServiceReverse::Scenario::UNDEFINED));
917         auto ret = service->InitIncrementalBackupSession(nullptr);
918         EXPECT_EQ(ret, BError(BError::Codes::EXT_THROW_EXCEPTION).GetCode());
919     } catch (...) {
920         EXPECT_TRUE(false);
921         GTEST_LOG_(INFO) << "ServiceThrowTest-an exception occurred by InitIncrementalBackupSession.";
922     }
923     GTEST_LOG_(INFO) << "ServiceThrowTest-end SUB_Service_throw_InitIncrementalBackupSession_0100";
924 }
925 
926 /**
927  * @tc.number: SUB_Service_throw_AppendBundlesIncrementalBackupSession_0100
928  * @tc.name: SUB_Service_throw_AppendBundlesIncrementalBackupSession_0100
929  * @tc.desc: 测试 AppendBundlesIncrementalBackupSession 接口的 catch 分支
930  * @tc.size: MEDIUM
931  * @tc.type: FUNC
932  * @tc.level Level 1
933  * @tc.require: issuesIAC04T
934  */
935 HWTEST_F(ServiceThrowTest, SUB_Service_throw_AppendBundlesIncrementalBackupSession_0100, testing::ext::TestSize.Level1)
936 {
937     GTEST_LOG_(INFO) << "ServiceThrowTest-begin SUB_Service_throw_AppendBundlesIncrementalBackupSession_0100";
938     try {
939         EXPECT_NE(service, nullptr);
940         vector<BIncrementalData> bundlesToBackup;
__anon410060db3e02() 941         EXPECT_CALL(*sessionMock, IncreaseSessionCnt(_)).WillOnce(Invoke([]() {
942             throw BError(BError::Codes::EXT_THROW_EXCEPTION);
943         }));
944         EXPECT_CALL(*sessionMock, DecreaseSessionCnt(_)).WillOnce(Return());
945         auto ret = service->AppendBundlesIncrementalBackupSession(bundlesToBackup);
946         EXPECT_EQ(ret, BError(BError::Codes::EXT_THROW_EXCEPTION).GetCode());
947 
__anon410060db3f02() 948         EXPECT_CALL(*sessionMock, IncreaseSessionCnt(_)).WillOnce(Invoke([]() {
949             throw "未知错误";
950         }));
951         EXPECT_CALL(*sessionMock, DecreaseSessionCnt(_)).WillOnce(Return());
952         ret = service->AppendBundlesIncrementalBackupSession(bundlesToBackup);
953         EXPECT_EQ(ret, EPERM);
954     } catch (...) {
955         EXPECT_TRUE(false);
956         GTEST_LOG_(INFO) << "ServiceThrowTest-an exception occurred by AppendBundlesIncrementalBackupSession.";
957     }
958     GTEST_LOG_(INFO) << "ServiceThrowTest-end SUB_Service_throw_AppendBundlesIncrementalBackupSession_0100";
959 }
960 
961 /**
962  * @tc.number: SUB_Service_throw_AppendBundlesIncrementalBackupSession_0200
963  * @tc.name: SUB_Service_throw_AppendBundlesIncrementalBackupSession_0200
964  * @tc.desc: 测试 AppendBundlesIncrementalBackupSession 接口的 catch 分支
965  * @tc.size: MEDIUM
966  * @tc.type: FUNC
967  * @tc.level Level 1
968  * @tc.require: issuesIAC04T
969  */
970 HWTEST_F(ServiceThrowTest, SUB_Service_throw_AppendBundlesIncrementalBackupSession_0200, testing::ext::TestSize.Level1)
971 {
972     GTEST_LOG_(INFO) << "ServiceThrowTest-begin SUB_Service_throw_AppendBundlesIncrementalBackupSession_0200";
973     try {
974         EXPECT_NE(service, nullptr);
975         vector<BIncrementalData> bundlesToBackup;
976         vector<std::string> infos;
__anon410060db4002() 977         EXPECT_CALL(*sessionMock, IncreaseSessionCnt(_)).WillOnce(Invoke([]() {
978             throw BError(BError::Codes::EXT_THROW_EXCEPTION);
979         }));
980         EXPECT_CALL(*sessionMock, DecreaseSessionCnt(_)).WillOnce(Return());
981         auto ret = service->AppendBundlesIncrementalBackupSession(bundlesToBackup, infos);
982         EXPECT_EQ(ret, BError(BError::Codes::EXT_THROW_EXCEPTION).GetCode());
983 
__anon410060db4102() 984         EXPECT_CALL(*sessionMock, IncreaseSessionCnt(_)).WillOnce(Invoke([]() {
985             throw "未知错误";
986         }));
987         EXPECT_CALL(*sessionMock, DecreaseSessionCnt(_)).WillOnce(Return());
988         ret = service->AppendBundlesIncrementalBackupSession(bundlesToBackup, infos);
989         EXPECT_EQ(ret, EPERM);
990     } catch (...) {
991         EXPECT_TRUE(false);
992         GTEST_LOG_(INFO) << "ServiceThrowTest-an exception occurred by AppendBundlesIncrementalBackupSession.";
993     }
994     GTEST_LOG_(INFO) << "ServiceThrowTest-end SUB_Service_throw_AppendBundlesIncrementalBackupSession_0200";
995 }
996 
997 /**
998  * @tc.number: SUB_Service_throw_PublishIncrementalFile_0100
999  * @tc.name: SUB_Service_throw_PublishIncrementalFile_0100
1000  * @tc.desc: 测试 PublishIncrementalFile 接口的 catch 分支
1001  * @tc.size: MEDIUM
1002  * @tc.type: FUNC
1003  * @tc.level Level 1
1004  * @tc.require: issuesIAC04T
1005  */
1006 HWTEST_F(ServiceThrowTest, SUB_Service_throw_PublishIncrementalFile_0100, testing::ext::TestSize.Level1)
1007 {
1008     GTEST_LOG_(INFO) << "ServiceThrowTest-begin SUB_Service_throw_PublishIncrementalFile_0100";
1009     try {
1010         EXPECT_NE(service, nullptr);
1011         BFileInfo fileInfo;
__anon410060db4202() 1012         EXPECT_CALL(*sessionMock, VerifyCallerAndScenario(_, _)).WillOnce(Invoke([]() {
1013             throw BError(BError::Codes::EXT_THROW_EXCEPTION);
1014         }));
1015         auto ret = service->PublishIncrementalFile(fileInfo);
1016         EXPECT_EQ(ret, BError(BError::Codes::EXT_THROW_EXCEPTION).GetCode());
1017 
__anon410060db4302() 1018         EXPECT_CALL(*sessionMock, VerifyCallerAndScenario(_, _)).WillOnce(Invoke([]() {
1019             throw runtime_error("运行时错误");
1020         }));
1021         ret = service->PublishIncrementalFile(fileInfo);
1022         EXPECT_EQ(ret, EPERM);
1023 
__anon410060db4402() 1024         EXPECT_CALL(*sessionMock, VerifyCallerAndScenario(_, _)).WillOnce(Invoke([]() {
1025             throw "未知错误";
1026         }));
1027         ret = service->PublishIncrementalFile(fileInfo);
1028         EXPECT_EQ(ret, EPERM);
1029     } catch (...) {
1030         EXPECT_TRUE(false);
1031         GTEST_LOG_(INFO) << "ServiceThrowTest-an exception occurred by PublishIncrementalFile.";
1032     }
1033     GTEST_LOG_(INFO) << "ServiceThrowTest-end SUB_Service_throw_PublishIncrementalFile_0100";
1034 }
1035 
1036 /**
1037  * @tc.number: SUB_Service_throw_AppIncrementalFileReady_0100
1038  * @tc.name: SUB_Service_throw_AppIncrementalFileReady_0100
1039  * @tc.desc: 测试 AppIncrementalFileReady 接口的 catch 分支
1040  * @tc.size: MEDIUM
1041  * @tc.type: FUNC
1042  * @tc.level Level 1
1043  * @tc.require: issuesIAC04T
1044  */
1045 HWTEST_F(ServiceThrowTest, SUB_Service_throw_AppIncrementalFileReady_0100, testing::ext::TestSize.Level1)
1046 {
1047     GTEST_LOG_(INFO) << "ServiceThrowTest-begin SUB_Service_throw_AppIncrementalFileReady_0100";
1048     try {
1049         EXPECT_NE(service, nullptr);
1050         string fileName;
__anon410060db4502() 1051         EXPECT_CALL(*sessionMock, VerifyBundleName(_)).WillOnce(Invoke([]() {
1052             throw BError(BError::Codes::EXT_THROW_EXCEPTION);
1053         }));
1054         auto ret = service->AppIncrementalFileReady(fileName, UniqueFd(-1), UniqueFd(-1), 0);
1055         EXPECT_EQ(ret, BError(BError::Codes::EXT_THROW_EXCEPTION).GetCode());
1056 
__anon410060db4602() 1057         EXPECT_CALL(*sessionMock, VerifyBundleName(_)).WillOnce(Invoke([]() {
1058             throw runtime_error("运行时错误");
1059         }));
1060         ret = service->AppIncrementalFileReady(fileName, UniqueFd(-1), UniqueFd(-1), 0);
1061         EXPECT_EQ(ret, EPERM);
1062 
__anon410060db4702() 1063         EXPECT_CALL(*sessionMock, VerifyBundleName(_)).WillOnce(Invoke([]() {
1064             throw "未知错误";
1065         }));
1066         ret = service->AppIncrementalFileReady(fileName, UniqueFd(-1), UniqueFd(-1), 0);
1067         EXPECT_EQ(ret, EPERM);
1068     } catch (...) {
1069         EXPECT_TRUE(false);
1070         GTEST_LOG_(INFO) << "ServiceThrowTest-an exception occurred by AppIncrementalFileReady.";
1071     }
1072     GTEST_LOG_(INFO) << "ServiceThrowTest-end SUB_Service_throw_AppIncrementalFileReady_0100";
1073 }
1074 
1075 /**
1076  * @tc.number: SUB_Service_throw_AppIncrementalDone_0100
1077  * @tc.name: SUB_Service_throw_AppIncrementalDone_0100
1078  * @tc.desc: 测试 AppIncrementalDone 接口的 catch 分支
1079  * @tc.size: MEDIUM
1080  * @tc.type: FUNC
1081  * @tc.level Level 1
1082  * @tc.require: issuesIAC04T
1083  */
1084 HWTEST_F(ServiceThrowTest, SUB_Service_throw_AppIncrementalDone_0100, testing::ext::TestSize.Level1)
1085 {
1086     GTEST_LOG_(INFO) << "ServiceThrowTest-begin SUB_Service_throw_AppIncrementalDone_0100";
1087     try {
1088         EXPECT_NE(service, nullptr);
__anon410060db4802() 1089         EXPECT_CALL(*sessionMock, VerifyBundleName(_)).WillOnce(Invoke([]() {
1090             throw BError(BError::Codes::EXT_THROW_EXCEPTION);
1091         }));
1092         EXPECT_CALL(*sessionMock, IsOnAllBundlesFinished()).WillOnce(Return(false));
1093         auto ret = service->AppIncrementalDone(0);
1094         EXPECT_EQ(ret, BError(BError::Codes::EXT_THROW_EXCEPTION).GetCode());
1095 
__anon410060db4902() 1096         EXPECT_CALL(*sessionMock, VerifyBundleName(_)).WillOnce(Invoke([]() {
1097             throw "未知错误";
1098         }));
1099         EXPECT_CALL(*sessionMock, IsOnAllBundlesFinished()).WillOnce(Return(false));
1100         ret = service->AppIncrementalDone(0);
1101         EXPECT_EQ(ret, EPERM);
1102     } catch (...) {
1103         EXPECT_TRUE(false);
1104         GTEST_LOG_(INFO) << "ServiceThrowTest-an exception occurred by AppIncrementalDone.";
1105     }
1106     GTEST_LOG_(INFO) << "ServiceThrowTest-end SUB_Service_throw_AppIncrementalDone_0100";
1107 }
1108 
1109 /**
1110  * @tc.number: SUB_Service_throw_GetIncrementalFileHandle_0100
1111  * @tc.name: SUB_Service_throw_GetIncrementalFileHandle_0100
1112  * @tc.desc: 测试 GetIncrementalFileHandle 接口的 catch 分支
1113  * @tc.size: MEDIUM
1114  * @tc.type: FUNC
1115  * @tc.level Level 1
1116  * @tc.require: issuesIAC04T
1117  */
1118 HWTEST_F(ServiceThrowTest, SUB_Service_throw_GetIncrementalFileHandle_0100, testing::ext::TestSize.Level1)
1119 {
1120     GTEST_LOG_(INFO) << "ServiceThrowTest-begin SUB_Service_throw_GetIncrementalFileHandle_0100";
1121     try {
1122         EXPECT_NE(service, nullptr);
1123         string bundleName;
1124         string fileName;
__anon410060db4a02() 1125         EXPECT_CALL(*sessionMock, VerifyCallerAndScenario(_, _)).WillOnce(Invoke([]() {
1126             throw BError(BError::Codes::EXT_THROW_EXCEPTION);
1127         }));
1128         auto ret = service->GetIncrementalFileHandle(bundleName, fileName);
1129         EXPECT_EQ(ret, BError(BError::Codes::EXT_THROW_EXCEPTION).GetCode());
1130 
__anon410060db4b02() 1131         EXPECT_CALL(*sessionMock, VerifyCallerAndScenario(_, _)).WillOnce(Invoke([]() {
1132             throw runtime_error("运行时错误");
1133         }));
1134         ret = service->GetIncrementalFileHandle(bundleName, fileName);
1135         EXPECT_EQ(ret, EPERM);
1136 
__anon410060db4c02() 1137         EXPECT_CALL(*sessionMock, VerifyCallerAndScenario(_, _)).WillOnce(Invoke([]() {
1138             throw "未知错误";
1139         }));
1140         ret = service->GetIncrementalFileHandle(bundleName, fileName);
1141         EXPECT_EQ(ret, EPERM);
1142     } catch (...) {
1143         EXPECT_TRUE(false);
1144         GTEST_LOG_(INFO) << "ServiceThrowTest-an exception occurred by GetIncrementalFileHandle.";
1145     }
1146     GTEST_LOG_(INFO) << "ServiceThrowTest-end SUB_Service_throw_GetIncrementalFileHandle_0100";
1147 }
1148 } // namespace OHOS::FileManagement::Backup