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 "b_error/b_error.h"
19 #include "b_incremental_backup_session.h"
20 #include "b_incremental_restore_session.h"
21 #include "b_incremental_session_restore_async.h"
22 #include "service_proxy_mock.h"
23
24 namespace OHOS::FileManagement::Backup {
25 using namespace std;
26 using namespace testing;
27
28 class IncrementalSessionTest : public testing::Test {
29 public:
30 static void SetUpTestCase(void);
31 static void TearDownTestCase();
SetUp()32 void SetUp() override {};
TearDown()33 void TearDown() override {};
34 public:
35 static inline sptr<ServiceProxyMock> proxy = nullptr;
36 static inline shared_ptr<BIncrementalBackupSession> backupSession = nullptr;
37 static inline shared_ptr<BIncrementalRestoreSession> restoreSession = nullptr;
38 static inline shared_ptr<BIncrementalSessionRestoreAsync> restoreAsyncSession = nullptr;
39 };
40
SetUpTestCase()41 void IncrementalSessionTest::SetUpTestCase()
42 {
43 proxy = sptr<ServiceProxyMock>(new ServiceProxyMock(nullptr));
44 backupSession = make_shared<BIncrementalBackupSession>();
45 restoreSession = make_shared<BIncrementalRestoreSession>();
46 BIncrementalSessionRestoreAsync::Callbacks callbacks;
47 restoreAsyncSession = make_shared<BIncrementalSessionRestoreAsync>(callbacks);
48 ServiceProxy::serviceProxy_ = proxy;
49 }
50
TearDownTestCase()51 void IncrementalSessionTest::TearDownTestCase()
52 {
53 backupSession = nullptr;
54 restoreSession = nullptr;
55 restoreAsyncSession = nullptr;
56 ServiceProxy::serviceProxy_ = nullptr;
57 proxy = nullptr;
58 }
59
60 /**
61 * @tc.number: SUB_b_incremental_session_test_0100
62 * @tc.name: SUB_b_incremental_session_test_0100
63 * @tc.desc: 测试 InitRestoreSession 接口
64 * @tc.size: MEDIUM
65 * @tc.type: FUNC
66 * @tc.level Level 1
67 * @tc.require: issuesI9KPRL
68 */
69 HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_0100, testing::ext::TestSize.Level1)
70 {
71 GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_0100";
72 try {
73 ServiceProxy::serviceProxy_ = nullptr;
74 BIncrementalBackupSession::Callbacks callbacks;
75 EXPECT_TRUE(backupSession != nullptr);
76 auto err = backupSession->Init(callbacks);
77 EXPECT_EQ(err, nullptr);
78
79 EXPECT_CALL(*proxy, InitIncrementalBackupSession(_)).WillOnce(Return(-1)).WillOnce(Return(0));
80 ServiceProxy::serviceProxy_ = proxy;
81 err = backupSession->Init(callbacks);
82 EXPECT_EQ(err, nullptr);
83 err = backupSession->Init(callbacks);
84 EXPECT_NE(err, nullptr);
85 } catch (...) {
86 EXPECT_TRUE(false);
87 GTEST_LOG_(INFO) << "IncrementalSessionTest-an exception occurred by RemoveExtConn.";
88 }
89 GTEST_LOG_(INFO) << "IncrementalSessionTest-end SUB_b_incremental_session_test_0100";
90 }
91
BackupSeviceDied()92 void BackupSeviceDied() {}
93 /**
94 * @tc.number: SUB_b_incremental_session_test_0200
95 * @tc.name: SUB_b_incremental_session_test_0200
96 * @tc.desc: 测试 RegisterBackupServiceDied 接口
97 * @tc.size: MEDIUM
98 * @tc.type: FUNC
99 * @tc.level Level 1
100 * @tc.require: issuesI9KPRL
101 */
102 HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_0200, testing::ext::TestSize.Level1)
103 {
104 GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_0200";
105 try {
106 ServiceProxy::serviceProxy_ = nullptr;
107 EXPECT_TRUE(backupSession != nullptr);
108 backupSession->RegisterBackupServiceDied(nullptr);
109
110 ServiceProxy::serviceProxy_ = proxy;
111 backupSession->RegisterBackupServiceDied(nullptr);
112
113 EXPECT_CALL(*proxy, AsObject()).WillOnce(Return(nullptr));
114 backupSession->RegisterBackupServiceDied(BackupSeviceDied);
115 } catch (...) {
116 EXPECT_TRUE(true);
117 GTEST_LOG_(INFO) << "IncrementalSessionTest-an exception occurred by RemoveExtConn.";
118 }
119 GTEST_LOG_(INFO) << "IncrementalSessionTest-end SUB_b_incremental_session_test_0200";
120 }
121
122 /**
123 * @tc.number: SUB_b_incremental_session_test_0300
124 * @tc.name: SUB_b_incremental_session_test_0300
125 * @tc.desc: 测试 AppendBundles 接口
126 * @tc.size: MEDIUM
127 * @tc.type: FUNC
128 * @tc.level Level 1
129 * @tc.require: issuesI9KPRL
130 */
131 HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_0300, testing::ext::TestSize.Level1)
132 {
133 GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_0300";
134 try {
135 ServiceProxy::serviceProxy_ = nullptr;
136 vector<BIncrementalData> bundlesToBackup;
137 EXPECT_TRUE(backupSession != nullptr);
138 auto err = backupSession->AppendBundles(bundlesToBackup);
139 EXPECT_EQ(err, BError(BError::Codes::SDK_BROKEN_IPC).GetCode());
140
141 EXPECT_CALL(*proxy, AppendBundlesIncrementalBackupSession(_)).WillOnce(Return(0));
142 ServiceProxy::serviceProxy_ = proxy;
143 err = backupSession->AppendBundles(bundlesToBackup);
144 EXPECT_EQ(err, BError(BError::Codes::OK).GetCode());
145 } catch (...) {
146 EXPECT_TRUE(true);
147 GTEST_LOG_(INFO) << "IncrementalSessionTest-an exception occurred by RemoveExtConn.";
148 }
149 GTEST_LOG_(INFO) << "IncrementalSessionTest-end SUB_b_incremental_session_test_0300";
150 }
151
152 /**
153 * @tc.number: SUB_b_incremental_session_test_0400
154 * @tc.name: SUB_b_incremental_session_test_0400
155 * @tc.desc: 测试 Release 接口
156 * @tc.size: MEDIUM
157 * @tc.type: FUNC
158 * @tc.level Level 1
159 * @tc.require: issuesI9KPRL
160 */
161 HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_0400, testing::ext::TestSize.Level1)
162 {
163 GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_0400";
164 try {
165 ServiceProxy::serviceProxy_ = nullptr;
166 EXPECT_TRUE(backupSession != nullptr);
167 auto err = backupSession->Release();
168 EXPECT_EQ(err, BError(BError::Codes::SDK_BROKEN_IPC).GetCode());
169
170 EXPECT_CALL(*proxy, Release()).WillOnce(Return(0));
171 ServiceProxy::serviceProxy_ = proxy;
172 err = backupSession->Release();
173 EXPECT_EQ(err, BError(BError::Codes::OK).GetCode());
174 } catch (...) {
175 EXPECT_TRUE(false);
176 GTEST_LOG_(INFO) << "IncrementalSessionTest-an exception occurred by RemoveExtConn.";
177 }
178 GTEST_LOG_(INFO) << "IncrementalSessionTest-end SUB_b_incremental_session_test_0400";
179 }
180
181 /**
182 * @tc.number: SUB_b_incremental_session_test_0500
183 * @tc.name: SUB_b_incremental_session_test_0500
184 * @tc.desc: 测试 Init 接口
185 * @tc.size: MEDIUM
186 * @tc.type: FUNC
187 * @tc.level Level 1
188 * @tc.require: issuesI9KPRL
189 */
190 HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_0500, testing::ext::TestSize.Level1)
191 {
192 GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_0500";
193 try {
194 ServiceProxy::serviceProxy_ = nullptr;
195 BIncrementalRestoreSession::Callbacks callbacks;
196 EXPECT_TRUE(restoreSession != nullptr);
197 auto err = restoreSession->Init(callbacks);
198 EXPECT_EQ(err, nullptr);
199
200 EXPECT_CALL(*proxy, InitRestoreSession(_)).WillOnce(Return(-1)).WillOnce(Return(0));
201 ServiceProxy::serviceProxy_ = proxy;
202 err = restoreSession->Init(callbacks);
203 EXPECT_EQ(err, nullptr);
204 err = restoreSession->Init(callbacks);
205 EXPECT_NE(err, nullptr);
206 } catch (...) {
207 EXPECT_TRUE(false);
208 GTEST_LOG_(INFO) << "IncrementalSessionTest-an exception occurred by RemoveExtConn.";
209 }
210 GTEST_LOG_(INFO) << "IncrementalSessionTest-end SUB_b_incremental_session_test_0500";
211 }
212
RestoreSeviceDied()213 void RestoreSeviceDied() {}
214 /**
215 * @tc.number: SUB_b_incremental_session_test_0600
216 * @tc.name: SUB_b_incremental_session_test_0600
217 * @tc.desc: 测试 RegisterBackupServiceDied 接口
218 * @tc.size: MEDIUM
219 * @tc.type: FUNC
220 * @tc.level Level 1
221 * @tc.require: issuesI9KPRL
222 */
223 HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_0600, testing::ext::TestSize.Level1)
224 {
225 GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_0600";
226 try {
227 ServiceProxy::serviceProxy_ = nullptr;
228 EXPECT_TRUE(restoreSession != nullptr);
229 restoreSession->RegisterBackupServiceDied(nullptr);
230
231 ServiceProxy::serviceProxy_ = proxy;
232 restoreSession->RegisterBackupServiceDied(nullptr);
233
234 EXPECT_CALL(*proxy, AsObject()).WillOnce(Return(nullptr));
235 restoreSession->RegisterBackupServiceDied(RestoreSeviceDied);
236 } catch (...) {
237 EXPECT_TRUE(true);
238 GTEST_LOG_(INFO) << "IncrementalSessionTest-an exception occurred by RemoveExtConn.";
239 }
240 GTEST_LOG_(INFO) << "IncrementalSessionTest-end SUB_b_incremental_session_test_0600";
241 }
242
243 /**
244 * @tc.number: SUB_b_incremental_session_test_0700
245 * @tc.name: SUB_b_incremental_session_test_0700
246 * @tc.desc: 测试 AppendBundles 接口
247 * @tc.size: MEDIUM
248 * @tc.type: FUNC
249 * @tc.level Level 1
250 * @tc.require: issuesI9KPRL
251 */
252 HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_0700, testing::ext::TestSize.Level1)
253 {
254 GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_0700";
255 try {
256 ServiceProxy::serviceProxy_ = nullptr;
257 UniqueFd remoteCap1;
258 vector<BundleName> bundlesToRestore;
259 EXPECT_TRUE(restoreSession != nullptr);
260 auto err = restoreSession->AppendBundles(move(remoteCap1), bundlesToRestore);
261 EXPECT_EQ(err, BError(BError::Codes::SDK_BROKEN_IPC).GetCode());
262
263 EXPECT_CALL(*proxy, AppendBundlesRestoreSession(_, _, _, _)).WillOnce(Return(0));
264 UniqueFd remoteCap2;
265 ServiceProxy::serviceProxy_ = proxy;
266 err = restoreSession->AppendBundles(move(remoteCap2), bundlesToRestore);
267 EXPECT_EQ(err, BError(BError::Codes::OK).GetCode());
268 } catch (...) {
269 EXPECT_TRUE(true);
270 GTEST_LOG_(INFO) << "IncrementalSessionTest-an exception occurred by RemoveExtConn.";
271 }
272 GTEST_LOG_(INFO) << "IncrementalSessionTest-end SUB_b_incremental_session_test_0700";
273 }
274
275 /**
276 * @tc.number: SUB_b_incremental_session_test_0800
277 * @tc.name: SUB_b_incremental_session_test_0800
278 * @tc.desc: 测试 Release 接口
279 * @tc.size: MEDIUM
280 * @tc.type: FUNC
281 * @tc.level Level 1
282 * @tc.require: issuesI9KPRL
283 */
284 HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_0800, testing::ext::TestSize.Level1)
285 {
286 GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_0800";
287 try {
288 ServiceProxy::serviceProxy_ = nullptr;
289 EXPECT_TRUE(restoreSession != nullptr);
290 auto err = restoreSession->Release();
291 EXPECT_EQ(err, BError(BError::Codes::SDK_BROKEN_IPC).GetCode());
292
293 EXPECT_CALL(*proxy, Release()).WillOnce(Return(0));
294 ServiceProxy::serviceProxy_ = proxy;
295 err = restoreSession->Release();
296 EXPECT_EQ(err, BError(BError::Codes::OK).GetCode());
297 } catch (...) {
298 EXPECT_TRUE(false);
299 GTEST_LOG_(INFO) << "IncrementalSessionTest-an exception occurred by RemoveExtConn.";
300 }
301 GTEST_LOG_(INFO) << "IncrementalSessionTest-end SUB_b_incremental_session_test_0800";
302 }
303
304 /**
305 * @tc.number: SUB_b_incremental_session_test_0900
306 * @tc.name: SUB_b_incremental_session_test_0900
307 * @tc.desc: 测试 PublishFile 接口
308 * @tc.size: MEDIUM
309 * @tc.type: FUNC
310 * @tc.level Level 1
311 * @tc.require: issuesI9KPRL
312 */
313 HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_0900, testing::ext::TestSize.Level1)
314 {
315 GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_0900";
316 try {
317 ServiceProxy::serviceProxy_ = nullptr;
318 BFileInfo fileInfo;
319 EXPECT_TRUE(restoreSession != nullptr);
320 auto err = restoreSession->PublishFile(fileInfo);
321 EXPECT_EQ(err, BError(BError::Codes::SDK_BROKEN_IPC).GetCode());
322
323 EXPECT_CALL(*proxy, PublishIncrementalFile(_)).WillOnce(Return(0));
324 ServiceProxy::serviceProxy_ = proxy;
325 err = restoreSession->PublishFile(fileInfo);
326 EXPECT_EQ(err, BError(BError::Codes::OK).GetCode());
327 } catch (...) {
328 EXPECT_TRUE(true);
329 GTEST_LOG_(INFO) << "IncrementalSessionTest-an exception occurred by RemoveExtConn.";
330 }
331 GTEST_LOG_(INFO) << "IncrementalSessionTest-end SUB_b_incremental_session_test_0900";
332 }
333
334
335 /**
336 * @tc.number: SUB_b_incremental_session_test_1000
337 * @tc.name: SUB_b_incremental_session_test_1000
338 * @tc.desc: 测试 GetFileHandle 接口
339 * @tc.size: MEDIUM
340 * @tc.type: FUNC
341 * @tc.level Level 1
342 * @tc.require: issuesI9KPRL
343 */
344 HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_1000, testing::ext::TestSize.Level1)
345 {
346 GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_1000";
347 try {
348 ServiceProxy::serviceProxy_ = nullptr;
349 string bundleName;
350 string fileName;
351 EXPECT_TRUE(restoreSession != nullptr);
352 auto err = restoreSession->GetFileHandle(bundleName, fileName);
353 EXPECT_EQ(err, BError(BError::Codes::SDK_BROKEN_IPC).GetCode());
354
355 EXPECT_CALL(*proxy, GetIncrementalFileHandle(_, _)).WillOnce(Return(0));
356 ServiceProxy::serviceProxy_ = proxy;
357 err = restoreSession->GetFileHandle(bundleName, fileName);
358 EXPECT_EQ(err, BError(BError::Codes::OK).GetCode());
359 } catch (...) {
360 EXPECT_TRUE(true);
361 GTEST_LOG_(INFO) << "IncrementalSessionTest-an exception occurred by RemoveExtConn.";
362 }
363 GTEST_LOG_(INFO) << "IncrementalSessionTest-end SUB_b_incremental_session_test_1000";
364 }
365
366 /**
367 * @tc.number: SUB_b_incremental_session_test_1100
368 * @tc.name: SUB_b_incremental_session_test_1100
369 * @tc.desc: 测试 AppendBundles 接口
370 * @tc.size: MEDIUM
371 * @tc.type: FUNC
372 * @tc.level Level 1
373 * @tc.require: issuesI9KPRL
374 */
375 HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_1100, testing::ext::TestSize.Level1)
376 {
377 GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_1100";
378 try {
379 ServiceProxy::serviceProxy_ = nullptr;
380 UniqueFd remoteCap;
381 vector<BundleName> bundlesToRestore;
382 vector<std::string> detailInfos;
383 EXPECT_TRUE(restoreSession != nullptr);
384 auto err = restoreSession->AppendBundles(move(remoteCap), bundlesToRestore, detailInfos);
385 EXPECT_EQ(err, BError(BError::Codes::SDK_BROKEN_IPC).GetCode());
386
387 EXPECT_CALL(*proxy, AppendBundlesRestoreSession(_, _, _, _, _)).WillOnce(Return(0));
388 ServiceProxy::serviceProxy_ = proxy;
389 err = restoreSession->AppendBundles(move(remoteCap), bundlesToRestore, detailInfos);
390 EXPECT_EQ(err, BError(BError::Codes::OK).GetCode());
391 } catch (...) {
392 EXPECT_TRUE(true);
393 GTEST_LOG_(INFO) << "IncrementalSessionTest-an exception occurred by RemoveExtConn.";
394 }
395 GTEST_LOG_(INFO) << "IncrementalSessionTest-end SUB_b_incremental_session_test_1100";
396 }
397
398 /**
399 * @tc.number: SUB_b_incremental_session_test_1200
400 * @tc.name: SUB_b_incremental_session_test_1200
401 * @tc.desc: 测试 Init 接口
402 * @tc.size: MEDIUM
403 * @tc.type: FUNC
404 * @tc.level Level 1
405 * @tc.require: issuesI9KPRL
406 */
407 HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_1200, testing::ext::TestSize.Level1)
408 {
409 GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_1200";
410 try {
411 ServiceProxy::serviceProxy_ = nullptr;
412 BIncrementalSessionRestoreAsync::Callbacks callbacks;
413 EXPECT_TRUE(restoreAsyncSession != nullptr);
414 auto err = restoreAsyncSession->Init(callbacks);
415 EXPECT_EQ(err, nullptr);
416
417 EXPECT_CALL(*proxy, InitRestoreSession(_)).WillOnce(Return(-1)).WillOnce(Return(0));
418 ServiceProxy::serviceProxy_ = proxy;
419 err = restoreAsyncSession->Init(callbacks);
420 EXPECT_EQ(err, nullptr);
421 err = restoreAsyncSession->Init(callbacks);
422 EXPECT_NE(err, nullptr);
423 } catch (...) {
424 EXPECT_TRUE(false);
425 GTEST_LOG_(INFO) << "IncrementalSessionTest-an exception occurred by RemoveExtConn.";
426 }
427 GTEST_LOG_(INFO) << "IncrementalSessionTest-end SUB_b_incremental_session_test_1200";
428 }
429
RestoreAsyncSeviceDied()430 void RestoreAsyncSeviceDied() {}
431 /**
432 * @tc.number: SUB_b_incremental_session_test_1300
433 * @tc.name: SUB_b_incremental_session_test_1300
434 * @tc.desc: 测试 RegisterBackupServiceDied 接口
435 * @tc.size: MEDIUM
436 * @tc.type: FUNC
437 * @tc.level Level 1
438 * @tc.require: issuesI9KPRL
439 */
440 HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_1300, testing::ext::TestSize.Level1)
441 {
442 GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_1300";
443 try {
444 ServiceProxy::serviceProxy_ = nullptr;
445 EXPECT_TRUE(restoreAsyncSession != nullptr);
446 restoreAsyncSession->RegisterBackupServiceDied(nullptr);
447
448 ServiceProxy::serviceProxy_ = proxy;
449 restoreAsyncSession->RegisterBackupServiceDied(nullptr);
450
451 EXPECT_CALL(*proxy, AsObject()).WillOnce(Return(nullptr));
452 restoreAsyncSession->RegisterBackupServiceDied(RestoreAsyncSeviceDied);
453 } catch (...) {
454 EXPECT_TRUE(true);
455 GTEST_LOG_(INFO) << "IncrementalSessionTest-an exception occurred by RemoveExtConn.";
456 }
457 GTEST_LOG_(INFO) << "IncrementalSessionTest-end SUB_b_incremental_session_test_1300";
458 }
459
460 /**
461 * @tc.number: SUB_b_incremental_session_test_1400
462 * @tc.name: SUB_b_incremental_session_test_1400
463 * @tc.desc: 测试 AppendBundles 接口
464 * @tc.size: MEDIUM
465 * @tc.type: FUNC
466 * @tc.level Level 1
467 * @tc.require: issuesI9KPRL
468 */
469 HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_1400, testing::ext::TestSize.Level1)
470 {
471 GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_1400";
472 try {
473 ServiceProxy::serviceProxy_ = nullptr;
474 UniqueFd remoteCap1;
475 vector<BundleName> bundlesToRestore;
476 EXPECT_TRUE(restoreAsyncSession != nullptr);
477 auto err = restoreAsyncSession->AppendBundles(move(remoteCap1), bundlesToRestore);
478 EXPECT_EQ(err, BError(BError::Codes::SDK_BROKEN_IPC).GetCode());
479
480 EXPECT_CALL(*proxy, AppendBundlesRestoreSession(_, _, _, _)).WillOnce(Return(0));
481 UniqueFd remoteCap2;
482 ServiceProxy::serviceProxy_ = proxy;
483 err = restoreAsyncSession->AppendBundles(move(remoteCap2), bundlesToRestore);
484 EXPECT_EQ(err, BError(BError::Codes::OK).GetCode());
485 } catch (...) {
486 EXPECT_TRUE(true);
487 GTEST_LOG_(INFO) << "IncrementalSessionTest-an exception occurred by RemoveExtConn.";
488 }
489 GTEST_LOG_(INFO) << "IncrementalSessionTest-end SUB_b_incremental_session_test_1400";
490 }
491
492 /**
493 * @tc.number: SUB_b_incremental_session_test_1500
494 * @tc.name: SUB_b_incremental_session_test_1500
495 * @tc.desc: 测试 PublishFile 接口
496 * @tc.size: MEDIUM
497 * @tc.type: FUNC
498 * @tc.level Level 1
499 * @tc.require: issuesI9KPRL
500 */
501 HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_1500, testing::ext::TestSize.Level1)
502 {
503 GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_1500";
504 try {
505 ServiceProxy::serviceProxy_ = nullptr;
506 BFileInfo fileInfo;
507 EXPECT_TRUE(restoreAsyncSession != nullptr);
508 auto err = restoreAsyncSession->PublishFile(fileInfo);
509 EXPECT_EQ(err, BError(BError::Codes::SDK_BROKEN_IPC).GetCode());
510
511 EXPECT_CALL(*proxy, PublishIncrementalFile(_)).WillOnce(Return(0));
512 ServiceProxy::serviceProxy_ = proxy;
513 err = restoreAsyncSession->PublishFile(fileInfo);
514 EXPECT_EQ(err, BError(BError::Codes::OK).GetCode());
515 } catch (...) {
516 EXPECT_TRUE(true);
517 GTEST_LOG_(INFO) << "IncrementalSessionTest-an exception occurred by RemoveExtConn.";
518 }
519 GTEST_LOG_(INFO) << "IncrementalSessionTest-end SUB_b_incremental_session_test_1500";
520 }
521
522
523 /**
524 * @tc.number: SUB_b_incremental_session_test_1600
525 * @tc.name: SUB_b_incremental_session_test_1600
526 * @tc.desc: 测试 GetFileHandle 接口
527 * @tc.size: MEDIUM
528 * @tc.type: FUNC
529 * @tc.level Level 1
530 * @tc.require: issuesI9KPRL
531 */
532 HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_1600, testing::ext::TestSize.Level1)
533 {
534 GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_1600";
535 try {
536 ServiceProxy::serviceProxy_ = nullptr;
537 string bundleName;
538 string fileName;
539 EXPECT_TRUE(restoreAsyncSession != nullptr);
540 auto err = restoreAsyncSession->GetFileHandle(bundleName, fileName);
541 EXPECT_EQ(err, BError(BError::Codes::SDK_BROKEN_IPC).GetCode());
542
543 EXPECT_CALL(*proxy, GetIncrementalFileHandle(_, _)).WillOnce(Return(0));
544 ServiceProxy::serviceProxy_ = proxy;
545 err = restoreAsyncSession->GetFileHandle(bundleName, fileName);
546 EXPECT_EQ(err, BError(BError::Codes::OK).GetCode());
547 } catch (...) {
548 EXPECT_TRUE(true);
549 GTEST_LOG_(INFO) << "IncrementalSessionTest-an exception occurred by RemoveExtConn.";
550 }
551 GTEST_LOG_(INFO) << "IncrementalSessionTest-end SUB_b_incremental_session_test_1600";
552 }
553
554 /**
555 * @tc.number: SUB_b_incremental_session_test_1700
556 * @tc.name: SUB_b_incremental_session_test_1700
557 * @tc.desc: 测试 AppendBundles 接口
558 * @tc.size: MEDIUM
559 * @tc.type: FUNC
560 * @tc.level Level 1
561 * @tc.require: issuesI9KPRL
562 */
563 HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_1700, testing::ext::TestSize.Level1)
564 {
565 GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_1700";
566 try {
567 ServiceProxy::serviceProxy_ = nullptr;
568 UniqueFd remoteCap;
569 vector<BundleName> bundlesToRestore;
570 vector<std::string> detailInfos;
571 EXPECT_TRUE(restoreAsyncSession != nullptr);
572 auto err = restoreAsyncSession->AppendBundles(move(remoteCap), bundlesToRestore, detailInfos);
573 EXPECT_EQ(err, BError(BError::Codes::SDK_BROKEN_IPC).GetCode());
574
575 EXPECT_CALL(*proxy, AppendBundlesRestoreSession(_, _, _, _, _)).WillOnce(Return(0));
576 ServiceProxy::serviceProxy_ = proxy;
577 err = restoreAsyncSession->AppendBundles(move(remoteCap), bundlesToRestore, detailInfos);
578 EXPECT_EQ(err, BError(BError::Codes::OK).GetCode());
579 } catch (...) {
580 EXPECT_TRUE(true);
581 GTEST_LOG_(INFO) << "IncrementalSessionTest-an exception occurred by RemoveExtConn.";
582 }
583 GTEST_LOG_(INFO) << "IncrementalSessionTest-end SUB_b_incremental_session_test_1700";
584 }
585
586 /**
587 * @tc.number: SUB_b_incremental_session_test_1800
588 * @tc.name: SUB_b_incremental_session_test_1800
589 * @tc.desc: 测试 Release 接口
590 * @tc.size: MEDIUM
591 * @tc.type: FUNC
592 * @tc.level Level 1
593 * @tc.require: issuesI9KPRL
594 */
595 HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_1800, testing::ext::TestSize.Level1)
596 {
597 GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_1800";
598 try {
599 ServiceProxy::serviceProxy_ = nullptr;
600 EXPECT_TRUE(restoreAsyncSession != nullptr);
601 auto err = restoreAsyncSession->Release();
602 EXPECT_EQ(err, BError(BError::Codes::SDK_BROKEN_IPC).GetCode());
603
604 EXPECT_CALL(*proxy, Release()).WillOnce(Return(0));
605 ServiceProxy::serviceProxy_ = proxy;
606 err = restoreAsyncSession->Release();
607 EXPECT_EQ(err, BError(BError::Codes::OK).GetCode());
608 } catch (...) {
609 EXPECT_TRUE(false);
610 GTEST_LOG_(INFO) << "IncrementalSessionTest-an exception occurred by RemoveExtConn.";
611 }
612 GTEST_LOG_(INFO) << "IncrementalSessionTest-end SUB_b_incremental_session_test_1800";
613 }
614
615 /**
616 * @tc.number: SUB_b_incremental_session_test_1900
617 * @tc.name: SUB_b_incremental_session_test_1900
618 * @tc.desc: 测试 AppendBundles 接口
619 * @tc.size: MEDIUM
620 * @tc.type: FUNC
621 * @tc.level Level 1
622 * @tc.require: issuesI9KPRL
623 */
624 HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_1900, testing::ext::TestSize.Level1)
625 {
626 GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_1900";
627 try {
628 ServiceProxy::serviceProxy_ = nullptr;
629 vector<BIncrementalData> bundlesToBackup;
630 vector<std::string> infos;
631 EXPECT_TRUE(backupSession != nullptr);
632 auto err = backupSession->AppendBundles(bundlesToBackup, infos);
633 EXPECT_EQ(err, BError(BError::Codes::SDK_BROKEN_IPC).GetCode());
634
635 EXPECT_CALL(*proxy, AppendBundlesIncrementalBackupSession(_, _)).WillOnce(Return(0));
636 ServiceProxy::serviceProxy_ = proxy;
637 err = backupSession->AppendBundles(bundlesToBackup, infos);
638 EXPECT_EQ(err, BError(BError::Codes::OK).GetCode());
639 } catch (...) {
640 EXPECT_TRUE(true);
641 GTEST_LOG_(INFO) << "IncrementalSessionTest-an exception occurred by RemoveExtConn.";
642 }
643 GTEST_LOG_(INFO) << "IncrementalSessionTest-end SUB_b_incremental_session_test_1900";
644 }
645
646 /**
647 * @tc.number: SUB_b_incremental_session_test_2000
648 * @tc.name: SUB_b_incremental_session_test_2000
649 * @tc.desc: 测试 PublishSAFile 接口
650 * @tc.size: MEDIUM
651 * @tc.type: FUNC
652 * @tc.level Level 1
653 * @tc.require: issuesI9KPRL
654 */
655 HWTEST_F(IncrementalSessionTest, SUB_b_incremental_session_test_2000, testing::ext::TestSize.Level1)
656 {
657 GTEST_LOG_(INFO) << "IncrementalSessionTest-begin SUB_b_incremental_session_test_2000";
658 try {
659 ServiceProxy::serviceProxy_ = nullptr;
660 BFileInfo fileInfo;
661 UniqueFd fd;
662 EXPECT_TRUE(restoreSession != nullptr);
663 auto err = restoreSession->PublishSAFile(fileInfo, move(fd));
664 EXPECT_EQ(err, BError(BError::Codes::SDK_BROKEN_IPC).GetCode());
665
666 EXPECT_CALL(*proxy, PublishIncrementalFile(_)).WillOnce(Return(0));
667 ServiceProxy::serviceProxy_ = proxy;
668 err = restoreSession->PublishSAFile(fileInfo, move(fd));
669 EXPECT_EQ(err, BError(BError::Codes::OK).GetCode());
670 } catch (...) {
671 EXPECT_TRUE(true);
672 GTEST_LOG_(INFO) << "IncrementalSessionTest-an exception occurred by RemoveExtConn.";
673 }
674 GTEST_LOG_(INFO) << "IncrementalSessionTest-end SUB_b_incremental_session_test_2000";
675 }
676 } // namespace OHOS::FileManagement::Backup