1 /*
2 * Copyright (c) 2022-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 <fcntl.h>
17 #include <gtest/gtest.h>
18 #include <string>
19 #include <sys/stat.h>
20 #include <sys/types.h>
21
22 #include "module_ipc/service.h"
23 #include "service_reverse_mock.h"
24 #include "test_manager.h"
25
26 #include "service.cpp"
27 #include "sub_service.cpp"
28
29 namespace OHOS::FileManagement::Backup {
30 using namespace std;
31 using namespace testing;
32
33 namespace {
34 const string BUNDLE_NAME = "com.example.app2backup";
35 const string MANAGE_JSON = "manage.json";
36 const string FILE_NAME = "1.tar";
37 constexpr int32_t SERVICE_ID = 5203;
38 } // namespace
39
40 class ServiceTest : public testing::Test {
41 public:
42 static void SetUpTestCase(void);
43 static void TearDownTestCase();
SetUp()44 void SetUp() {};
TearDown()45 void TearDown() {};
46
47 ErrCode Init(IServiceReverse::Scenario scenario);
48
49 static inline sptr<Service> servicePtr_ = nullptr;
50 static inline sptr<ServiceReverseMock> remote_ = nullptr;
51 };
52
SetUpTestCase(void)53 void ServiceTest::SetUpTestCase(void)
54 {
55 GTEST_LOG_(INFO) << "SetUpTestCase enter";
56 servicePtr_ = sptr<Service>(new Service(SERVICE_ID));
57 remote_ = sptr(new ServiceReverseMock());
58 }
59
TearDownTestCase()60 void ServiceTest::TearDownTestCase()
61 {
62 GTEST_LOG_(INFO) << "TearDownTestCase enter";
63 servicePtr_ = nullptr;
64 remote_ = nullptr;
65 }
66
Init(IServiceReverse::Scenario scenario)67 ErrCode ServiceTest::Init(IServiceReverse::Scenario scenario)
68 {
69 vector<string> bundleNames;
70 vector<string> detailInfos;
71 string json = "[{\"infos\":[{"
72 "\"details\":[{"
73 "\"detail\":[{"
74 "\"source\":\"com.app.demo001\","
75 "\"target\":\"com.example.fileonrestoreex\""
76 "}],"
77 "\"type\":\"app_mapping_relation\""
78 "}],"
79 "\"type\":\"broadcast\""
80 "}]"
81 "}]";
82 bundleNames.emplace_back(BUNDLE_NAME);
83 detailInfos.emplace_back(json);
84 string errMsg;
85 ErrCode ret = 0;
86 if (scenario == IServiceReverse::Scenario::RESTORE) {
87 EXPECT_TRUE(servicePtr_ != nullptr);
88 EXPECT_TRUE(remote_ != nullptr);
89 UniqueFd fd = servicePtr_->GetLocalCapabilities();
90 EXPECT_GE(fd, BError(BError::Codes::OK));
91 ret = servicePtr_->InitRestoreSession(remote_);
92 EXPECT_EQ(ret, BError(BError::Codes::OK));
93 ret = servicePtr_->InitRestoreSession(remote_, errMsg);
94 EXPECT_EQ(ret, BError(BError::Codes::OK));
95 ret = servicePtr_->AppendBundlesRestoreSession(move(fd), bundleNames, detailInfos);
96 EXPECT_EQ(ret, BError(BError::Codes::OK));
97 ret = servicePtr_->Finish();
98 EXPECT_EQ(ret, BError(BError::Codes::OK));
99 } else if (scenario == IServiceReverse::Scenario::BACKUP) {
100 ret = servicePtr_->InitBackupSession(remote_);
101 EXPECT_EQ(ret, BError(BError::Codes::OK));
102 ret = servicePtr_->InitBackupSession(remote_, errMsg);
103 EXPECT_EQ(ret, BError(BError::Codes::OK));
104 ret = servicePtr_->AppendBundlesBackupSession(bundleNames);
105 EXPECT_EQ(ret, BError(BError::Codes::OK));
106 ret = servicePtr_->Finish();
107 EXPECT_EQ(ret, BError(BError::Codes::OK));
108 }
109 return ret;
110 }
111
112 /**
113 * @tc.number: SUB_Service_GetLocalCapabilities_0100
114 * @tc.name: SUB_Service_GetLocalCapabilities_0100
115 * @tc.desc: 测试 GetLocalCapabilities 获取本地能力文件
116 * @tc.size: MEDIUM
117 * @tc.type: FUNC
118 * @tc.level Level 1
119 * @tc.require: I6F3GV
120 */
121 HWTEST_F(ServiceTest, SUB_Service_GetLocalCapabilities_0100, testing::ext::TestSize.Level1)
122 {
123 GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_GetLocalCapabilities_0100";
124 try {
125 EXPECT_TRUE(servicePtr_ != nullptr);
126 UniqueFd fd = servicePtr_->GetLocalCapabilities();
127 EXPECT_GT(fd, BError(BError::Codes::OK));
128 } catch (...) {
129 EXPECT_TRUE(false);
130 GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by GetLocalCapabilities.";
131 }
132 GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_GetLocalCapabilities_0100";
133 }
134
135 /**
136 * @tc.number: SUB_Service_GetLocalCapabilities_0101
137 * @tc.name: SUB_Service_GetLocalCapabilities_0101
138 * @tc.desc: 测试 GetLocalCapabilities 获取本地能力文件
139 * @tc.size: MEDIUM
140 * @tc.type: FUNC
141 * @tc.level Level 1
142 * @tc.require: I6F3GV
143 */
144 HWTEST_F(ServiceTest, SUB_Service_GetLocalCapabilities_0101, testing::ext::TestSize.Level1)
145 {
146 GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_GetLocalCapabilities_0101";
147 try {
148 EXPECT_TRUE(servicePtr_ != nullptr);
149 UniqueFd fd = servicePtr_->GetLocalCapabilities();
150 EXPECT_GT(fd, -EPERM);
151 } catch (...) {
152 EXPECT_TRUE(false);
153 GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by GetLocalCapabilities.";
154 }
155 GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_GetLocalCapabilities_0101";
156 }
157
158 /**
159 * @tc.number: SUB_Service_OnStart_0100
160 * @tc.name: SUB_Service_OnStart_0100
161 * @tc.desc: 测试 OnStart 接口
162 * @tc.size: MEDIUM
163 * @tc.type: FUNC
164 * @tc.level Level 1
165 * @tc.require: I6F3GV
166 */
167 HWTEST_F(ServiceTest, SUB_Service_OnStart_0100, testing::ext::TestSize.Level1)
168 {
169 GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_OnStart_0100";
170 try {
171 EXPECT_TRUE(servicePtr_ != nullptr);
172 servicePtr_->OnStart();
173 } catch (...) {
174 EXPECT_TRUE(false);
175 GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by OnStart.";
176 }
177 GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_OnStart_0100";
178 }
179
180 /**
181 * @tc.number: SUB_Service_Start_0100
182 * @tc.name: SUB_Service_Start_0100
183 * @tc.desc: 测试 Start 备份恢复启动
184 * @tc.size: MEDIUM
185 * @tc.type: FUNC
186 * @tc.level Level 1
187 * @tc.require: I6F3GV
188 */
189 HWTEST_F(ServiceTest, SUB_Service_Start_0100, testing::ext::TestSize.Level1)
190 {
191 GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_Start_0100";
192 try {
193 EXPECT_TRUE(servicePtr_ != nullptr);
194 auto ret = servicePtr_->Start();
195 EXPECT_EQ(ret, BError(BError::Codes::OK));
196 } catch (...) {
197 EXPECT_TRUE(false);
198 GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by Start.";
199 }
200 GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_Start_0100";
201 }
202
203 /**
204 * @tc.number: SUB_Service_PublishFile_0100
205 * @tc.name: SUB_Service_PublishFile_0100
206 * @tc.desc: 测试 PublishFile 接口
207 * @tc.size: MEDIUM
208 * @tc.type: FUNC
209 * @tc.level Level 1
210 * @tc.require: I6F3GV
211 */
212 HWTEST_F(ServiceTest, SUB_Service_PublishFile_0100, testing::ext::TestSize.Level1)
213 {
214 GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_PublishFile_0100";
215 try {
216 ErrCode ret = Init(IServiceReverse::Scenario::RESTORE);
217 EXPECT_EQ(ret, BError(BError::Codes::OK));
218 BFileInfo fileInfo {BUNDLE_NAME, "", 0};
219 EXPECT_TRUE(servicePtr_ != nullptr);
220 ret = servicePtr_->PublishFile(fileInfo);
221 EXPECT_EQ(ret, BError(BError::Codes::OK));
222 GTEST_LOG_(INFO) << "ServiceTest-PublishFile Branches";
223 fileInfo.fileName = "test";
224 ret = servicePtr_->PublishFile(fileInfo);
225 EXPECT_NE(ret, BError(BError::Codes::OK));
226 } catch (...) {
227 EXPECT_TRUE(false);
228 GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by PublishFile.";
229 }
230 GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_PublishFile_0100";
231 }
232
233 /**
234 * @tc.number: SUB_Service_PublishFile_0101
235 * @tc.name: SUB_Service_PublishFile_0101
236 * @tc.desc: 测试 PublishFile 接口
237 * @tc.size: MEDIUM
238 * @tc.type: FUNC
239 * @tc.level Level 1
240 * @tc.require: I6F3GV
241 */
242 HWTEST_F(ServiceTest, SUB_Service_PublishFile_0101, testing::ext::TestSize.Level1)
243 {
244 GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_PublishFile_0101";
245 try {
246 ErrCode ret = Init(IServiceReverse::Scenario::RESTORE);
247 EXPECT_EQ(ret, BError(BError::Codes::OK));
248 BFileInfo fileInfo {BUNDLE_NAME, "", 0};
249 EXPECT_TRUE(servicePtr_ != nullptr);
250 ret = servicePtr_->PublishFile(fileInfo);
251 EXPECT_EQ(ret, BError(BError::Codes::OK));
252 GTEST_LOG_(INFO) << "ServiceTest-PublishFile Branches";
253 fileInfo.fileName = "/data/storage/el2/restore/bundle.hap";
254 ret = servicePtr_->PublishFile(fileInfo);
255 EXPECT_NE(ret, BError(BError::Codes::OK));
256 } catch (...) {
257 EXPECT_TRUE(false);
258 GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by PublishFile.";
259 }
260 GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_PublishFile_0101";
261 }
262
263 /**
264 * @tc.number: SUB_Service_PublishFile_0102
265 * @tc.name: SUB_Service_PublishFile_0102
266 * @tc.desc: 测试 PublishFile 接口
267 * @tc.size: MEDIUM
268 * @tc.type: FUNC
269 * @tc.level Level 1
270 * @tc.require: I6F3GV
271 */
272 HWTEST_F(ServiceTest, SUB_Service_PublishFile_0102, testing::ext::TestSize.Level1)
273 {
274 GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_PublishFile_0102";
275 try {
276 ErrCode ret = Init(IServiceReverse::Scenario::RESTORE);
277 EXPECT_EQ(ret, BError(BError::Codes::OK));
278 BFileInfo fileInfo {BUNDLE_NAME, "", 0};
279 EXPECT_TRUE(servicePtr_ != nullptr);
280 ret = servicePtr_->PublishFile(fileInfo);
281 EXPECT_EQ(ret, BError(BError::Codes::OK));
282 } catch (...) {
283 EXPECT_TRUE(false);
284 GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by PublishFile.";
285 }
286 GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_PublishFile_0102";
287 }
288
289 /**
290 * @tc.number: SUB_Service_AppFileReady_0100
291 * @tc.name: SUB_Service_AppFileReady_0100
292 * @tc.desc: 测试 AppFileReady 接口
293 * @tc.size: MEDIUM
294 * @tc.type: FUNC
295 * @tc.level Level 1
296 * @tc.require: I6F3GV
297 */
298 HWTEST_F(ServiceTest, SUB_Service_AppFileReady_0100, testing::ext::TestSize.Level1)
299 {
300 GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_AppFileReady_0100";
301 try {
302 string fileName = MANAGE_JSON;
303 EXPECT_TRUE(servicePtr_ != nullptr);
304 auto ret = servicePtr_->AppFileReady(fileName, UniqueFd(-1), 0);
305 EXPECT_EQ(ret, BError(BError::Codes::OK));
306 GTEST_LOG_(INFO) << "ServiceTest-AppFileReady Branches";
307 fileName = "test";
308 ret = servicePtr_->AppFileReady(fileName, UniqueFd(-1), 0);
309 EXPECT_EQ(ret, BError(BError::Codes::OK));
310 } catch (...) {
311 EXPECT_TRUE(false);
312 GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by AppFileReady.";
313 }
314 GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_AppFileReady_0100";
315 }
316
317 /**
318 * @tc.number: SUB_Service_AppFileReady_0101
319 * @tc.name: SUB_Service_AppFileReady_0101
320 * @tc.desc: 测试 AppFileReady 接口
321 * @tc.size: MEDIUM
322 * @tc.type: FUNC
323 * @tc.level Level 1
324 * @tc.require: I6F3GV
325 */
326 HWTEST_F(ServiceTest, SUB_Service_AppFileReady_0101, testing::ext::TestSize.Level1)
327 {
328 GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_AppFileReady_0101";
329 try {
330 string fileName = "";
331 EXPECT_TRUE(servicePtr_ != nullptr);
332 auto ret = servicePtr_->AppFileReady(fileName, UniqueFd(-1), 0);
333 EXPECT_EQ(ret, BError(BError::Codes::OK));
334 } catch (...) {
335 EXPECT_TRUE(false);
336 GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by AppFileReady.";
337 }
338 GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_AppFileReady_0101";
339 }
340
341 /**
342 * @tc.number: SUB_Service_AppFileReady_0102
343 * @tc.name: SUB_Service_AppFileReady_0102
344 * @tc.desc: 测试 AppFileReady 接口
345 * @tc.size: MEDIUM
346 * @tc.type: FUNC
347 * @tc.level Level 1
348 * @tc.require: I6F3GV
349 */
350 HWTEST_F(ServiceTest, SUB_Service_AppFileReady_0102, testing::ext::TestSize.Level1)
351 {
352 GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_AppFileReady_0102";
353 try {
354 string fileName = "manage.json";
355 EXPECT_TRUE(servicePtr_ != nullptr);
356 auto ret = servicePtr_->AppFileReady(fileName, UniqueFd(-1), 0);
357 EXPECT_EQ(ret, BError(BError::Codes::OK));
358 } catch (...) {
359 EXPECT_TRUE(false);
360 GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by AppFileReady.";
361 }
362 GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_AppFileReady_0102";
363 }
364
365 /**
366 * @tc.number: SUB_Service_AppFileReady_0103
367 * @tc.name: SUB_Service_AppFileReady_0103
368 * @tc.desc: 测试 AppFileReady 接口
369 * @tc.size: MEDIUM
370 * @tc.type: FUNC
371 * @tc.level Level 1
372 * @tc.require: I6F3GV
373 */
374 HWTEST_F(ServiceTest, SUB_Service_AppFileReady_0103, testing::ext::TestSize.Level1)
375 {
376 GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_AppFileReady_0103";
377 try {
378 string fileName = "/manage.json";
379 EXPECT_TRUE(servicePtr_ != nullptr);
380 auto ret = servicePtr_->AppFileReady(fileName, UniqueFd(-1), 0);
381 EXPECT_EQ(ret, BError(BError::Codes::SA_INVAL_ARG));
382 } catch (...) {
383 EXPECT_TRUE(false);
384 GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by AppFileReady.";
385 }
386 GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_AppFileReady_0103";
387 }
388
389 /**
390 * @tc.number: SUB_Service_AppDone_0100
391 * @tc.name: SUB_Service_AppDone_0100
392 * @tc.desc: 测试 AppDone 接口
393 * @tc.size: MEDIUM
394 * @tc.type: FUNC
395 * @tc.level Level 1
396 * @tc.require: I6F3GV
397 */
398 HWTEST_F(ServiceTest, SUB_Service_AppDone_0100, testing::ext::TestSize.Level1)
399 {
400 GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_AppDone_0100";
401 try {
402 GTEST_LOG_(INFO) << "SUB_Service_AppDone Branches Start";
403 EXPECT_TRUE(servicePtr_ != nullptr);
404 auto ret = servicePtr_->AppDone(BError(BError::Codes::OK));
405 EXPECT_EQ(ret, BError(BError::Codes::OK));
406 GTEST_LOG_(INFO) << "SUB_Service_AppDone_0100 BACKUP";
407 ret = Init(IServiceReverse::Scenario::BACKUP);
408 EXPECT_EQ(ret, BError(BError::Codes::OK));
409 GTEST_LOG_(INFO) << "ServiceTest-AppDone Branches";
410 ret = servicePtr_->AppDone(1);
411 EXPECT_EQ(ret, BError(BError::Codes::OK));
412 GTEST_LOG_(INFO) << "ServiceTest-AppDone Branches End";
413 ret = servicePtr_->AppDone(BError(BError::Codes::OK));
414 EXPECT_EQ(ret, BError(BError::Codes::OK));
415 } catch (...) {
416 EXPECT_TRUE(false);
417 GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by AppDone.";
418 }
419 GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_AppDone_0100";
420 }
421
422 /**
423 * @tc.number: SUB_Service_AppDone_0101
424 * @tc.name: SUB_Service_AppDone_0101
425 * @tc.desc: 测试 AppDone 接口
426 * @tc.size: MEDIUM
427 * @tc.type: FUNC
428 * @tc.level Level 1
429 * @tc.require: I6F3GV
430 */
431 HWTEST_F(ServiceTest, SUB_Service_AppDone_0101, testing::ext::TestSize.Level1)
432 {
433 GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_AppDone_0101";
434 try {
435 GTEST_LOG_(INFO) << "SUB_Service_AppDone Branches Start";
436 EXPECT_TRUE(servicePtr_ != nullptr);
437 auto ret = servicePtr_->AppDone(BError(BError::Codes::OK));
438 EXPECT_EQ(ret, BError(BError::Codes::OK));
439 GTEST_LOG_(INFO) << "SUB_Service_AppDone_0101 RESTORE";
440 ret = Init(IServiceReverse::Scenario::RESTORE);
441 EXPECT_EQ(ret, BError(BError::Codes::OK));
442 ret = servicePtr_->AppDone(BError(BError::Codes::OK));
443 EXPECT_EQ(ret, BError(BError::Codes::OK));
444 } catch (...) {
445 EXPECT_TRUE(false);
446 GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by AppDone.";
447 }
448 GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_AppDone_0101";
449 }
450
451 /**
452 * @tc.number: SUB_Service_AppDone_0102
453 * @tc.name: SUB_Service_AppDone_0102
454 * @tc.desc: 测试 AppDone 接口
455 * @tc.size: MEDIUM
456 * @tc.type: FUNC
457 * @tc.level Level 1
458 * @tc.require: I6F3GV
459 */
460 HWTEST_F(ServiceTest, SUB_Service_AppDone_0102, testing::ext::TestSize.Level1)
461 {
462 GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_AppDone_0102";
463 try {
464 GTEST_LOG_(INFO) << "SUB_Service_AppDone Branches Start";
465 string bundleName = "";
466 EXPECT_TRUE(servicePtr_ != nullptr);
467 auto ret = servicePtr_->AppDone(BError(BError::Codes::OK));
468 EXPECT_EQ(ret, BError(BError::Codes::OK));
469 } catch (...) {
470 EXPECT_TRUE(false);
471 GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by AppDone.";
472 }
473 GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_AppDone_0102";
474 }
475
476 /**
477 * @tc.number: SUB_Service_ServiceResultReport_0000
478 * @tc.name: SUB_Service_ServiceResultReport_0000
479 * @tc.desc: 测试 ServiceResultReport 接口
480 * @tc.size: MEDIUM
481 * @tc.type: FUNC
482 * @tc.level Level 1
483 * @tc.require: I6F3GV
484 */
485 HWTEST_F(ServiceTest, SUB_Service_ServiceResultReport_0000, testing::ext::TestSize.Level1)
486 {
487 GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_ServiceResultReport_0000";
488 try {
489 GTEST_LOG_(INFO) << "SUB_Service_ServiceResultReport Branches Start";
490 string bundleName = "";
491 EXPECT_TRUE(servicePtr_ != nullptr);
492 auto ret = servicePtr_->ServiceResultReport("test", BackupRestoreScenario::FULL_RESTORE, 0);
493 EXPECT_EQ(ret, BError(BError::Codes::OK));
494
495 ret = servicePtr_->ServiceResultReport("test", BackupRestoreScenario::INCREMENTAL_RESTORE, 0);
496 EXPECT_EQ(ret, BError(BError::Codes::OK));
497
498 ret = servicePtr_->ServiceResultReport("test", BackupRestoreScenario::FULL_BACKUP, 0);
499 EXPECT_EQ(ret, BError(BError::Codes::OK));
500
501 ret = servicePtr_->ServiceResultReport("test", BackupRestoreScenario::INCREMENTAL_BACKUP, 0);
502 EXPECT_EQ(ret, BError(BError::Codes::OK));
503
504 ret = servicePtr_->ServiceResultReport("test", static_cast<BackupRestoreScenario>(1000), 0);
505 EXPECT_EQ(ret, BError(BError::Codes::OK));
506 } catch (...) {
507 EXPECT_TRUE(false);
508 GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by ServiceResultReport.";
509 }
510 GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_ServiceResultReport_0000";
511 }
512
513 /**
514 * @tc.number: SUB_Service_LaunchBackupExtension_0100
515 * @tc.name: SUB_Service_LaunchBackupExtension_0100
516 * @tc.desc: 测试 LaunchBackupExtension 接口
517 * @tc.size: MEDIUM
518 * @tc.type: FUNC
519 * @tc.level Level 1
520 * @tc.require: I6F3GV
521 */
522 HWTEST_F(ServiceTest, SUB_Service_LaunchBackupExtension_0100, testing::ext::TestSize.Level1)
523 {
524 GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_LaunchBackupExtension_0100";
525 try {
526 GTEST_LOG_(INFO) << "SUB_Service_LaunchBackupExtension_0100 RESTORE";
527 ErrCode ret = Init(IServiceReverse::Scenario::RESTORE);
528 EXPECT_EQ(ret, BError(BError::Codes::OK));
529 EXPECT_TRUE(servicePtr_ != nullptr);
530 ret = servicePtr_->LaunchBackupExtension(BUNDLE_NAME);
531 EXPECT_EQ(ret, BError(BError::Codes::OK));
532 GTEST_LOG_(INFO) << "SUB_Service_LaunchBackupExtension_0100 BACKUP";
533 ret = Init(IServiceReverse::Scenario::BACKUP);
534 EXPECT_EQ(ret, BError(BError::Codes::OK));
535 ret = servicePtr_->LaunchBackupExtension(BUNDLE_NAME);
536 EXPECT_EQ(ret, BError(BError::Codes::OK));
537 } catch (...) {
538 EXPECT_TRUE(false);
539 GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by LaunchBackupExtension.";
540 }
541 GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_LaunchBackupExtension_0100";
542 }
543
544 /**
545 * @tc.number: SUB_Service_LaunchBackupExtension_0101
546 * @tc.name: SUB_Service_LaunchBackupExtension_0101
547 * @tc.desc: 测试 LaunchBackupExtension 接口
548 * @tc.size: MEDIUM
549 * @tc.type: FUNC
550 * @tc.level Level 1
551 * @tc.require: I6F3GV
552 */
553 HWTEST_F(ServiceTest, SUB_Service_LaunchBackupExtension_0101, testing::ext::TestSize.Level1)
554 {
555 GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_LaunchBackupExtension_0101";
556 try {
557 GTEST_LOG_(INFO) << "SUB_Service_LaunchBackupExtension_0100 UNDEFINED";
558 ErrCode ret = Init(IServiceReverse::Scenario::UNDEFINED);
559 EXPECT_EQ(ret, BError(BError::Codes::OK));
560 EXPECT_TRUE(servicePtr_ != nullptr);
561 ret = servicePtr_->LaunchBackupExtension(BUNDLE_NAME);
562 EXPECT_EQ(ret, BError(BError::Codes::OK));
563 } catch (...) {
564 EXPECT_TRUE(false);
565 GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by LaunchBackupExtension.";
566 }
567 GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_LaunchBackupExtension_0101";
568 }
569
570 /**
571 * @tc.number: SUB_Service_GetFileHandle_0100
572 * @tc.name: SUB_Service_GetFileHandle_0100
573 * @tc.desc: 测试 GetFileHandle 接口
574 * @tc.size: MEDIUM
575 * @tc.type: FUNC
576 * @tc.level Level 1
577 * @tc.require: I6F3GV
578 */
579 HWTEST_F(ServiceTest, SUB_Service_GetFileHandle_0100, testing::ext::TestSize.Level1)
580 {
581 GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_GetFileHandle_0100";
582 try {
583 ErrCode ret = Init(IServiceReverse::Scenario::RESTORE);
584 EXPECT_EQ(ret, BError(BError::Codes::OK));
585 EXPECT_TRUE(servicePtr_ != nullptr);
586 ret = servicePtr_->GetFileHandle(BUNDLE_NAME, FILE_NAME);
587 EXPECT_EQ(ret, BError(BError::Codes::OK));
588 } catch (...) {
589 EXPECT_TRUE(false);
590 GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by GetFileHandle.";
591 }
592 GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_GetFileHandle_0100";
593 }
594
595 /**
596 * @tc.number: SUB_Service_GetFileHandle_0101
597 * @tc.name: SUB_Service_GetFileHandle_0101
598 * @tc.desc: 测试 GetFileHandle 接口
599 * @tc.size: MEDIUM
600 * @tc.type: FUNC
601 * @tc.level Level 1
602 * @tc.require: I6F3GV
603 */
604 HWTEST_F(ServiceTest, SUB_Service_GetFileHandle_0101, testing::ext::TestSize.Level1)
605 {
606 GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_GetFileHandle_0101";
607 try {
608 ErrCode ret = Init(IServiceReverse::Scenario::RESTORE);
609 EXPECT_EQ(ret, BError(BError::Codes::OK));
610
611 SvcSessionManager::Impl impl_;
612 impl_.clientToken = 1;
613 BackupExtInfo extInfo {};
__anon858d7f470202(const string &&bundleName, bool isCleanCalled) 614 auto callDied = [](const string &&bundleName, bool isCleanCalled) {};
__anon858d7f470302(const string &&bundleName) 615 auto callConnected = [](const string &&bundleName) {};
616 string bundleNameIndexInfo = "123456";
617 extInfo.backUpConnection = sptr(new SvcBackupConnection(callDied, callConnected, bundleNameIndexInfo));
618 extInfo.schedAction = BConstants::ServiceSchedAction::RUNNING;
619 impl_.backupExtNameMap[BUNDLE_NAME] = extInfo;
620 EXPECT_TRUE(servicePtr_ != nullptr);
621 ret = servicePtr_->GetFileHandle(BUNDLE_NAME, FILE_NAME);
622 EXPECT_EQ(ret, BError(BError::Codes::OK));
623 } catch (...) {
624 EXPECT_TRUE(false);
625 GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by GetFileHandle.";
626 }
627 GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_GetFileHandle_0101";
628 }
629
630 /**
631 * @tc.number: SUB_Service_OnBackupExtensionDied_0100
632 * @tc.name: SUB_Service_OnBackupExtensionDied_0100
633 * @tc.desc: 测试 OnBackupExtensionDied 接口
634 * @tc.size: MEDIUM
635 * @tc.type: FUNC
636 * @tc.level Level 1
637 * @tc.require: I6F3GV
638 */
639 HWTEST_F(ServiceTest, SUB_Service_OnBackupExtensionDied_0100, testing::ext::TestSize.Level1)
640 {
641 GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_OnBackupExtensionDied_0100";
642 try {
643 GTEST_LOG_(INFO) << "SUB_Service_OnBackupExtensionDied_0100 RESTORE";
644 ErrCode ret = Init(IServiceReverse::Scenario::RESTORE);
645 EXPECT_EQ(ret, BError(BError::Codes::OK));
646 string bundleName = BUNDLE_NAME;
647 EXPECT_TRUE(servicePtr_ != nullptr);
648 servicePtr_->OnBackupExtensionDied(move(bundleName));
649 GTEST_LOG_(INFO) << "SUB_Service_OnBackupExtensionDied_0100 BACKUP";
650 ret = Init(IServiceReverse::Scenario::BACKUP);
651 EXPECT_EQ(ret, BError(BError::Codes::OK));
652 bundleName = BUNDLE_NAME;
653 servicePtr_->OnBackupExtensionDied(move(bundleName));
654 } catch (...) {
655 EXPECT_TRUE(false);
656 GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by GetFileHandle.";
657 }
658 GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_OnBackupExtensionDied_0100";
659 }
660
661 /**
662 * @tc.number: SUB_Service_OnBackupExtensionDied_0101
663 * @tc.name: SUB_Service_OnBackupExtensionDied_0101
664 * @tc.desc: 测试 OnBackupExtensionDied 接口
665 * @tc.size: MEDIUM
666 * @tc.type: FUNC
667 * @tc.level Level 1
668 * @tc.require: I6F3GV
669 */
670 HWTEST_F(ServiceTest, SUB_Service_OnBackupExtensionDied_0101, testing::ext::TestSize.Level1)
671 {
672 GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_OnBackupExtensionDied_0101";
673 try {
674 GTEST_LOG_(INFO) << "SUB_Service_OnBackupExtensionDied_0101 RESTORE";
675 ErrCode ret = Init(IServiceReverse::Scenario::RESTORE);
676 EXPECT_EQ(ret, BError(BError::Codes::OK));
677 string bundleName = BUNDLE_NAME;
678 SvcSessionManager::Impl impl_;
679 impl_.clientToken = 1;
680 BackupExtInfo extInfo {};
681 extInfo.backUpConnection = nullptr;
682 extInfo.versionName = "0.0.0.0-0.0.0.0";
683 impl_.restoreDataType = RESTORE_DATA_WAIT_SEND;
684 impl_.backupExtNameMap[BUNDLE_NAME] = extInfo;
685 impl_.scenario = IServiceReverse::Scenario::RESTORE;
686 EXPECT_TRUE(servicePtr_ != nullptr);
687 servicePtr_->OnBackupExtensionDied(move(bundleName));
688 GTEST_LOG_(INFO) << "SUB_Service_OnBackupExtensionDied_0101 BACKUP";
689
690 ret = Init(IServiceReverse::Scenario::BACKUP);
691 EXPECT_EQ(ret, BError(BError::Codes::OK));
692 impl_.restoreDataType = RESTORE_DATA_READDY;
693 bundleName = "123456789";
694 impl_.backupExtNameMap[bundleName] = extInfo;
695 servicePtr_->OnBackupExtensionDied(move(bundleName));
696 } catch (...) {
697 EXPECT_TRUE(false);
698 GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by GetFileHandle.";
699 }
700 GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_OnBackupExtensionDied_0101";
701 }
702
703 /**
704 * @tc.number: SUB_Service_ExtStart_0100
705 * @tc.name: SUB_Service_ExtStart_0100
706 * @tc.desc: 测试 ExtStart 接口
707 * @tc.size: MEDIUM
708 * @tc.type: FUNC
709 * @tc.level Level 1
710 * @tc.require: I6F3GV
711 */
712 HWTEST_F(ServiceTest, SUB_Service_ExtStart_0100, testing::ext::TestSize.Level1)
713 {
714 GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_ExtStart_0100";
715 try {
716 GTEST_LOG_(INFO) << "SUB_Service_ExtStart_0100 BACKUP";
717 ErrCode ret = Init(IServiceReverse::Scenario::BACKUP);
718 EXPECT_EQ(ret, BError(BError::Codes::OK));
719 EXPECT_TRUE(servicePtr_ != nullptr);
720 servicePtr_->ExtStart(BUNDLE_NAME);
721 GTEST_LOG_(INFO) << "ServiceTest-ExtStart BACKUP Branches";
722 servicePtr_->ExtStart(BUNDLE_NAME);
723 GTEST_LOG_(INFO) << "SUB_Service_ExtStart_0100 RESTORE";
724 ret = Init(IServiceReverse::Scenario::RESTORE);
725 servicePtr_->ExtStart(BUNDLE_NAME);
726 } catch (...) {
727 EXPECT_TRUE(false);
728 GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by ExtStart.";
729 }
730 GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_ExtStart_0100";
731 }
732
733 /**
734 * @tc.number: SUB_Service_ExtStart_0101
735 * @tc.name: SUB_Service_ExtStart_0101
736 * @tc.desc: 测试 ExtStart 接口
737 * @tc.size: MEDIUM
738 * @tc.type: FUNC
739 * @tc.level Level 1
740 * @tc.require: I6F3GV
741 */
742 HWTEST_F(ServiceTest, SUB_Service_ExtStart_0101, testing::ext::TestSize.Level1)
743 {
744 GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_ExtStart_0101";
745 try {
746 GTEST_LOG_(INFO) << "SUB_Service_ExtStart_0101 BACKUP";
747 std::string bundleName = "123456";
748 ErrCode ret = Init(IServiceReverse::Scenario::BACKUP);
749 EXPECT_EQ(ret, BError(BError::Codes::OK));
750 EXPECT_TRUE(servicePtr_ != nullptr);
751 servicePtr_->ExtStart(bundleName);
752
753 GTEST_LOG_(INFO) << "SUB_Service_ExtStart_0101 RESTORE";
754 SvcSessionManager::Impl impl_;
755 impl_.clientToken = 1;
756 BackupExtInfo extInfo {};
__anon858d7f470402(const string &&bundleName, bool isCleanCalled) 757 auto callDied = [](const string &&bundleName, bool isCleanCalled) {};
__anon858d7f470502(const string &&bundleName) 758 auto callConnected = [](const string &&bundleName) {};
759 string bundleNameIndexInfo = "123456789";
760 extInfo.backUpConnection = sptr(new SvcBackupConnection(callDied, callConnected, bundleNameIndexInfo));
761 extInfo.backUpConnection->backupProxy_ = nullptr;
762 impl_.backupExtNameMap[BUNDLE_NAME] = extInfo;
763 impl_.scenario = IServiceReverse::Scenario::UNDEFINED;
764 ret = Init(IServiceReverse::Scenario::UNDEFINED);
765 EXPECT_EQ(ret, BError(BError::Codes::OK));
766 servicePtr_->ExtStart(BUNDLE_NAME);
767
768 ret = Init(IServiceReverse::Scenario::RESTORE);
769 EXPECT_EQ(ret, BError(BError::Codes::OK));
770 servicePtr_->ExtStart(BUNDLE_NAME);
771
772 ret = Init(IServiceReverse::Scenario::UNDEFINED);
773 EXPECT_EQ(ret, BError(BError::Codes::OK));
774 servicePtr_->ExtStart(BUNDLE_NAME);
775 } catch (...) {
776 EXPECT_TRUE(false);
777 GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by ExtStart.";
778 }
779 GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_ExtStart_0101";
780 }
781
782 /**
783 * @tc.number: SUB_Service_Dump_0100
784 * @tc.name: SUB_Service_Dump_0100
785 * @tc.desc: 测试 Dump 接口
786 * @tc.size: MEDIUM
787 * @tc.type: FUNC
788 * @tc.level Level 1
789 * @tc.require: I6F3GV
790 */
791 HWTEST_F(ServiceTest, SUB_Service_Dump_0100, testing::ext::TestSize.Level1)
792 {
793 GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_Dump_0100";
794 try {
795 EXPECT_TRUE(servicePtr_ != nullptr);
796 servicePtr_->Dump(-1, {});
797 TestManager tm("ServiceTest_GetFd_0100");
798 string filePath = tm.GetRootDirCurTest().append(FILE_NAME);
799 UniqueFd fd(open(filePath.data(), O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR));
800 servicePtr_->Dump(move(fd), {});
801 } catch (...) {
802 EXPECT_TRUE(false);
803 GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by Dump.";
804 }
805 GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_Dump_0100";
806 }
807
808 /**
809 * @tc.number: SUB_Service_Dump_0101
810 * @tc.name: SUB_Service_Dump_0101
811 * @tc.desc: 测试 Dump 接口
812 * @tc.size: MEDIUM
813 * @tc.type: FUNC
814 * @tc.level Level 1
815 * @tc.require: I6F3GV
816 */
817 HWTEST_F(ServiceTest, SUB_Service_Dump_0101, testing::ext::TestSize.Level1)
818 {
819 GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_Dump_0101";
820 try {
821 EXPECT_TRUE(servicePtr_ != nullptr);
822 int ret = servicePtr_->Dump(1, {});
823 EXPECT_EQ(ret, 0);
824 } catch (...) {
825 EXPECT_TRUE(false);
826 GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by Dump.";
827 }
828 GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_Dump_0101";
829 }
830
831 /**
832 * @tc.number: SUB_Service_Dump_0102
833 * @tc.name: SUB_Service_Dump_0102
834 * @tc.desc: 测试 Dump 接口
835 * @tc.size: MEDIUM
836 * @tc.type: FUNC
837 * @tc.level Level 1
838 * @tc.require: I6F3GV
839 */
840 HWTEST_F(ServiceTest, SUB_Service_Dump_0102, testing::ext::TestSize.Level1)
841 {
842 GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_Dump_0102";
843 try {
844 EXPECT_TRUE(servicePtr_ != nullptr);
845 int ret = servicePtr_->Dump(-1, {});
846 EXPECT_EQ(ret, -1);
847 } catch (...) {
848 EXPECT_TRUE(false);
849 GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by Dump.";
850 }
851 GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_Dump_0102";
852 }
853
854 /**
855 * @tc.number: SUB_Service_ExtConnectFailed_0100
856 * @tc.name: SUB_Service_ExtConnectFailed_0100
857 * @tc.desc: 测试 ExtConnectFailed 接口
858 * @tc.size: MEDIUM
859 * @tc.type: FUNC
860 * @tc.level Level 1
861 * @tc.require: I6F3GV
862 */
863 HWTEST_F(ServiceTest, SUB_Service_ExtConnectFailed_0100, testing::ext::TestSize.Level1)
864 {
865 GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_ExtConnectFailed_0100";
866 try {
867 GTEST_LOG_(INFO) << "SUB_Service_ExtConnectFailed_0100 RESTORE";
868 ErrCode ret = Init(IServiceReverse::Scenario::RESTORE);
869 EXPECT_EQ(ret, BError(BError::Codes::OK));
870 EXPECT_TRUE(servicePtr_ != nullptr);
871 servicePtr_->ExtConnectFailed(BUNDLE_NAME, BError(BError::Codes::OK));
872 GTEST_LOG_(INFO) << "SUB_Service_ExtConnectFailed_0100 BACKUP";
873 ret = Init(IServiceReverse::Scenario::BACKUP);
874 EXPECT_EQ(ret, BError(BError::Codes::OK));
875 servicePtr_->ExtConnectFailed(BUNDLE_NAME, BError(BError::Codes::OK));
876
877 SvcSessionManager::Impl impl_;
878 impl_.clientToken = 1;
879 impl_.restoreDataType = RESTORE_DATA_READDY;
880 ret = Init(IServiceReverse::Scenario::RESTORE);
881 EXPECT_EQ(ret, BError(BError::Codes::OK));
882 servicePtr_->ExtConnectFailed(BUNDLE_NAME, BError(BError::Codes::OK));
883 } catch (...) {
884 EXPECT_TRUE(false);
885 GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by ExtConnectFailed.";
886 }
887 GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_ExtConnectFailed_0100";
888 }
889
890 /**
891 * @tc.number: SUB_Service_ExtConnectDone_0100
892 * @tc.name: SUB_Service_ExtConnectDone_0100
893 * @tc.desc: 测试 ExtConnectDone 接口
894 * @tc.size: MEDIUM
895 * @tc.type: FUNC
896 * @tc.level Level 1
897 * @tc.require: I6F3GV
898 */
899 HWTEST_F(ServiceTest, SUB_Service_ExtConnectDone_0100, testing::ext::TestSize.Level1)
900 {
901 GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_ExtConnectDone_0100";
902 try {
903 EXPECT_TRUE(servicePtr_ != nullptr);
904 servicePtr_->ExtConnectDone(BUNDLE_NAME);
905 } catch (...) {
906 EXPECT_TRUE(false);
907 GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by ExtConnectDone.";
908 }
909 GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_ExtConnectDone_0100";
910 }
911
912 /**
913 * @tc.number: SUB_Service_StopAll_0100
914 * @tc.name: SUB_Service_StopAll_0100
915 * @tc.desc: 测试 StopAll 接口
916 * @tc.size: MEDIUM
917 * @tc.type: FUNC
918 * @tc.level Level 1
919 * @tc.require: I6F3GV
920 */
921 HWTEST_F(ServiceTest, SUB_Service_StopAll_0100, testing::ext::TestSize.Level1)
922 {
923 GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_StopAll_0100";
924 try {
925 SvcSessionManager::Impl impl_;
926 impl_.clientToken = 0;
927 EXPECT_TRUE(servicePtr_ != nullptr);
928 servicePtr_->StopAll(nullptr, true);
929 } catch (...) {
930 EXPECT_TRUE(false);
931 GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by StopAll.";
932 }
933 GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_StopAll_0100";
934 }
935
936 /**
937 * @tc.number: SUB_Service_StopAll_0101
938 * @tc.name: SUB_Service_StopAll_0101
939 * @tc.desc: 测试 StopAll 接口
940 * @tc.size: MEDIUM
941 * @tc.type: FUNC
942 * @tc.level Level 1
943 * @tc.require: I6F3GV
944 */
945 HWTEST_F(ServiceTest, SUB_Service_StopAll_0101, testing::ext::TestSize.Level1)
946 {
947 GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_StopAll_0101";
948 try {
949 SvcSessionManager::Impl impl_;
950 impl_.clientProxy = nullptr;
951 EXPECT_TRUE(servicePtr_ != nullptr);
952 servicePtr_->StopAll(nullptr, true);
953 } catch (...) {
954 EXPECT_TRUE(false);
955 GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by StopAll.";
956 }
957 GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_StopAll_0101";
958 }
959
960 /**
961 * @tc.number: SUB_Service_StopAll_0102
962 * @tc.name: SUB_Service_StopAll_0102
963 * @tc.desc: 测试 StopAll 接口
964 * @tc.size: MEDIUM
965 * @tc.type: FUNC
966 * @tc.level Level 1
967 * @tc.require: I6F3GV
968 */
969 HWTEST_F(ServiceTest, SUB_Service_StopAll_0102, testing::ext::TestSize.Level1)
970 {
971 GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_StopAll_0102";
972 try {
973 SvcSessionManager::Impl impl_;
974 impl_.clientToken = 0;
975 EXPECT_TRUE(servicePtr_ != nullptr);
976 servicePtr_->StopAll(nullptr, false);
977 } catch (...) {
978 EXPECT_TRUE(false);
979 GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by StopAll.";
980 }
981 GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_StopAll_0102";
982 }
983
984 /**
985 * @tc.number: SUB_Service_StopAll_0103
986 * @tc.name: SUB_Service_StopAll_0103
987 * @tc.desc: 测试 StopAll 接口
988 * @tc.size: MEDIUM
989 * @tc.type: FUNC
990 * @tc.level Level 1
991 * @tc.require: I6F3GV
992 */
993 HWTEST_F(ServiceTest, SUB_Service_StopAll_0103, testing::ext::TestSize.Level1)
994 {
995 GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_StopAll_0103";
996 try {
997 SvcSessionManager::Impl impl_;
998 impl_.clientProxy = nullptr;
999 EXPECT_TRUE(servicePtr_ != nullptr);
1000 servicePtr_->StopAll(nullptr, false);
1001 } catch (...) {
1002 EXPECT_TRUE(false);
1003 GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by StopAll.";
1004 }
1005 GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_StopAll_0103";
1006 }
1007
1008 /**
1009 * @tc.number: SUB_Service_StopAll_0104
1010 * @tc.name: SUB_Service_StopAll_0104
1011 * @tc.desc: 测试 StopAll 接口
1012 * @tc.size: MEDIUM
1013 * @tc.type: FUNC
1014 * @tc.level Level 1
1015 * @tc.require: I6F3GV
1016 */
1017 HWTEST_F(ServiceTest, SUB_Service_StopAll_0104, testing::ext::TestSize.Level1)
1018 {
1019 GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_StopAll_0104";
1020 try {
1021 SvcSessionManager::Impl impl_;
1022 impl_.clientProxy = nullptr;
1023 const wptr<IRemoteObject> obj = nullptr;
1024 EXPECT_TRUE(servicePtr_ != nullptr);
1025 servicePtr_->StopAll(obj, false);
1026 } catch (...) {
1027 EXPECT_TRUE(false);
1028 GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by StopAll.";
1029 }
1030 GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_StopAll_0104";
1031 }
1032
1033 /**
1034 * @tc.number: SUB_Service_OnStop_0100
1035 * @tc.name: SUB_Service_OnStop_0100
1036 * @tc.desc: 测试 OnStop 接口
1037 * @tc.size: MEDIUM
1038 * @tc.type: FUNC
1039 * @tc.level Level 1
1040 * @tc.require: I6F3GV
1041 */
1042 HWTEST_F(ServiceTest, SUB_Service_OnStop_0100, testing::ext::TestSize.Level1)
1043 {
1044 GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_OnStop_0100";
1045 try {
1046 EXPECT_TRUE(servicePtr_ != nullptr);
1047 servicePtr_->OnStop();
1048 } catch (...) {
1049 EXPECT_TRUE(false);
1050 GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by OnStop.";
1051 }
1052 GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_OnStop_0100";
1053 }
1054
1055 /**
1056 * @tc.number: SUB_Service_SendStartAppGalleryNotify_0100
1057 * @tc.name: SUB_Service_SendStartAppGalleryNotify_0100
1058 * @tc.desc: 测试 SendStartAppGalleryNotify 接口
1059 * @tc.size: MEDIUM
1060 * @tc.type: FUNC
1061 * @tc.level Level 1
1062 * @tc.require: I8ZIMJ
1063 */
1064 HWTEST_F(ServiceTest, SUB_Service_SendStartAppGalleryNotify_0100, testing::ext::TestSize.Level1)
1065 {
1066 GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_SendStartAppGalleryNotify_0100";
1067 try {
1068 EXPECT_TRUE(servicePtr_ != nullptr);
1069 BundleName bundleName = "";
1070 servicePtr_->SendStartAppGalleryNotify(bundleName);
1071 } catch (...) {
1072 EXPECT_TRUE(false);
1073 GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by SendStartAppGalleryNotify.";
1074 }
1075 GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_SendStartAppGalleryNotify_0100";
1076 }
1077
1078 /**
1079 * @tc.number: SUB_Service_SendStartAppGalleryNotify_0101
1080 * @tc.name: SUB_Service_SendStartAppGalleryNotify_0101
1081 * @tc.desc: 测试 SendStartAppGalleryNotify 接口
1082 * @tc.size: MEDIUM
1083 * @tc.type: FUNC
1084 * @tc.level Level 1
1085 * @tc.require: I8ZIMJ
1086 */
1087 HWTEST_F(ServiceTest, SUB_Service_SendStartAppGalleryNotify_0101, testing::ext::TestSize.Level1)
1088 {
1089 GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_SendStartAppGalleryNotify_0101";
1090 try {
1091 ErrCode ret = Init(IServiceReverse::Scenario::RESTORE);
1092 EXPECT_EQ(ret, BError(BError::Codes::OK));
1093 EXPECT_TRUE(servicePtr_ != nullptr);
1094 servicePtr_->SendStartAppGalleryNotify(BUNDLE_NAME);
1095 } catch (...) {
1096 EXPECT_TRUE(false);
1097 GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by SendStartAppGalleryNotify.";
1098 }
1099 GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_SendStartAppGalleryNotify_0101";
1100 }
1101
1102 /**
1103 * @tc.number: SUB_Service_SessionDeactive_0100
1104 * @tc.name: SUB_Service_SessionDeactive_0100
1105 * @tc.desc: 测试 SessionDeactive 接口
1106 * @tc.size: MEDIUM
1107 * @tc.type: FUNC
1108 * @tc.level Level 1
1109 * @tc.require: I8ZIMJ
1110 */
1111 HWTEST_F(ServiceTest, SUB_Service_SessionDeactive_0100, testing::ext::TestSize.Level1)
1112 {
1113 GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_SessionDeactive_0100";
1114 try {
1115 EXPECT_TRUE(servicePtr_ != nullptr);
1116 servicePtr_->SessionDeactive();
1117 } catch (...) {
1118 EXPECT_TRUE(false);
1119 GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by SessionDeactive.";
1120 }
1121 GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_SessionDeactive_0100";
1122 }
1123
1124 /**
1125 * @tc.number: SUB_Service_GetBackupInfo_0100
1126 * @tc.name: SUB_Service_GetBackupInfo_0100
1127 * @tc.desc: 测试 SessionDeactive 接口
1128 * @tc.size: MEDIUM
1129 * @tc.type: FUNC
1130 * @tc.level Level 1
1131 * @tc.require: I8ZIMJ
1132 */
1133 HWTEST_F(ServiceTest, SUB_Service_GetBackupInfo_0100, testing::ext::TestSize.Level1)
1134 {
1135 GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_GetBackupInfo_0100";
1136 try {
1137 std::string bundleName = "com.example.app2backup";
1138 std::string backupInfo = "backup info";
1139 auto ret = Init(IServiceReverse::Scenario::BACKUP);
1140 EXPECT_EQ(ret, BError(BError::Codes::OK));
1141 EXPECT_TRUE(servicePtr_ != nullptr);
1142 servicePtr_->GetBackupInfo(bundleName, backupInfo);
1143 } catch (...) {
1144 EXPECT_TRUE(false);
1145 GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by GetBackupInfo.";
1146 }
1147 GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_GetBackupInfo_0100";
1148 }
1149
1150 /**
1151 * @tc.number: SUB_Service_GetBackupInfo_0101
1152 * @tc.name: SUB_Service_GetBackupInfo_0101
1153 * @tc.desc: 测试 SessionDeactive 接口
1154 * @tc.size: MEDIUM
1155 * @tc.type: FUNC
1156 * @tc.level Level 1
1157 * @tc.require: I8ZIMJ
1158 */
1159 HWTEST_F(ServiceTest, SUB_Service_GetBackupInfo_0101, testing::ext::TestSize.Level1)
1160 {
1161 GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_GetBackupInfo_0101";
1162 try {
1163 std::string bundleName = "com.example.app2backup";
1164 std::string result = "ok";
1165 auto ret = Init(IServiceReverse::Scenario::BACKUP);
1166 EXPECT_EQ(ret, BError(BError::Codes::OK));
1167 EXPECT_TRUE(servicePtr_ != nullptr);
1168 servicePtr_->session_ = nullptr;
1169 SvcSessionManager::Impl impl_;
1170 impl_.clientToken = 1;
1171 ret = servicePtr_->GetBackupInfo(bundleName, result);
1172 EXPECT_NE(ret, BError(BError::Codes::OK));
1173
1174 impl_.clientToken = 0;
1175 ret = servicePtr_->GetBackupInfo(bundleName, result);
1176 EXPECT_NE(ret, BError(BError::Codes::OK));
1177 } catch (...) {
1178 EXPECT_TRUE(false);
1179 GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by GetBackupInfo.";
1180 }
1181 GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_GetBackupInfo_0101";
1182 }
1183
1184 /**
1185 * @tc.number: SUB_Service_UpdateTimer_0100
1186 * @tc.name: SUB_Service_UpdateTimer_0100
1187 * @tc.desc: 测试 UpdateTimer 接口
1188 * @tc.size: MEDIUM
1189 * @tc.type: FUNC
1190 * @tc.level Level 1
1191 * @tc.require: I8ZIMJ
1192 */
1193 HWTEST_F(ServiceTest, SUB_Service_UpdateTimer_0100, testing::ext::TestSize.Level1)
1194 {
1195 GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_UpdateTimer_0100";
1196 try {
1197 std::string bundleName = "com.example.app2backup";
1198 bool result = true;
1199 uint32_t timeout = 30000;
1200 EXPECT_TRUE(servicePtr_ != nullptr);
1201 servicePtr_->UpdateTimer(bundleName, timeout, result);
1202 } catch (...) {
1203 EXPECT_TRUE(false);
1204 GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by UpdateTimer.";
1205 }
1206 GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_UpdateTimer_0100";
1207 }
1208
1209 /**
1210 * @tc.number: SUB_Service_UpdateTimer_0101
1211 * @tc.name: SUB_Service_UpdateTimer_0101
1212 * @tc.desc: 测试 UpdateTimer 接口
1213 * @tc.size: MEDIUM
1214 * @tc.type: FUNC
1215 * @tc.level Level 1
1216 * @tc.require: I8ZIMJ
1217 */
1218 HWTEST_F(ServiceTest, SUB_Service_UpdateTimer_0101, testing::ext::TestSize.Level1)
1219 {
1220 GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_UpdateTimer_0101";
1221 try {
1222 std::string bundleName = "com.example.app2backup";
1223 bool result = true;
1224 uint32_t timeout = 30000;
1225 EXPECT_TRUE(servicePtr_ != nullptr);
1226 servicePtr_->session_ = nullptr;
1227 servicePtr_->UpdateTimer(bundleName, timeout, result);
1228 } catch (...) {
1229 EXPECT_TRUE(false);
1230 GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by UpdateTimer.";
1231 }
1232 GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_UpdateTimer_0101";
1233 }
1234
1235 /**
1236 * @tc.number: SUB_Service_GetBackupInfoCmdHandle_0100
1237 * @tc.name: SUB_Service_GetBackupInfoCmdHandle_0100
1238 * @tc.desc: 测试 GetBackupInfoCmdHandle 接口
1239 * @tc.size: MEDIUM
1240 * @tc.type: FUNC
1241 * @tc.level Level 1
1242 * @tc.require: I8ZIMJ
1243 */
1244 HWTEST_F(ServiceTest, SUB_Service_GetBackupInfoCmdHandle_0100, testing::ext::TestSize.Level1)
1245 {
1246 GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_GetBackupInfoCmdHandle_0100";
1247 try {
1248 std::string bundleName = "com.example.app2backup";
1249 std::string result;
1250 EXPECT_TRUE(servicePtr_ != nullptr);
1251 auto ret = servicePtr_->GetBackupInfoCmdHandle(bundleName, result);
1252 EXPECT_TRUE(ret == BError::BackupErrorCode::E_INVAL);
1253 } catch (...) {
1254 EXPECT_TRUE(false);
1255 GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by GetBackupInfoCmdHandle.";
1256 }
1257 GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_GetBackupInfoCmdHandle_0100";
1258 }
1259
1260 /**
1261 * @tc.number: SUB_Service_SpecialVersion_0100
1262 * @tc.name: SUB_Service_SpecialVersion_0100
1263 * @tc.desc: 测试 SpecialVersion 接口
1264 * @tc.size: MEDIUM
1265 * @tc.type: FUNC
1266 * @tc.level Level 1
1267 * @tc.require: I8ZIMJ
1268 */
1269 HWTEST_F(ServiceTest, SUB_Service_SpecialVersion_0100, testing::ext::TestSize.Level1)
1270 {
1271 GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_SpecialVersion_0100";
1272 try {
1273 std::string versionName = "0.0.0.0-0.0.0.0";
1274 EXPECT_TRUE(servicePtr_ != nullptr);
1275 bool ret = SpecialVersion(versionName);
1276 EXPECT_EQ(ret, true);
1277 versionName = "1.1.1.1-1.1.1.1";
1278 ret = SpecialVersion(versionName);
1279 EXPECT_EQ(ret, false);
1280 } catch (...) {
1281 EXPECT_TRUE(false);
1282 GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by SpecialVersion.";
1283 }
1284 GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_SpecialVersion_0100";
1285 }
1286
1287 /**
1288 * @tc.number: SUB_Service_OnBundleStarted_0100
1289 * @tc.name: SUB_Service_OnBundleStarted_0100
1290 * @tc.desc: 测试 OnBundleStarted 接口
1291 * @tc.size: MEDIUM
1292 * @tc.type: FUNC
1293 * @tc.level Level 1
1294 * @tc.require: I8ZIMJ
1295 */
1296 HWTEST_F(ServiceTest, SUB_Service_OnBundleStarted_0100, testing::ext::TestSize.Level1)
1297 {
1298 GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_OnBundleStarted_0100";
1299 try {
1300 int32_t saID = 2503;
1301 wptr<Service> reversePtr(new Service(saID));
1302 sptr<SvcSessionManager> session(new SvcSessionManager(reversePtr));
1303 EXPECT_TRUE(servicePtr_ != nullptr);
1304 servicePtr_->OnBundleStarted(BError(BError::Codes::SA_INVAL_ARG), session, BUNDLE_NAME);
1305 SvcSessionManager::Impl impl_;
1306 impl_.clientToken = 1;
1307 impl_.scenario = IServiceReverse::Scenario::RESTORE;
1308 servicePtr_->OnBundleStarted(BError(BError::Codes::SA_INVAL_ARG), session, BUNDLE_NAME);
1309 } catch (...) {
1310 EXPECT_TRUE(false);
1311 GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by OnBundleStarted.";
1312 }
1313 GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_OnBundleStarted_0100";
1314 }
1315
1316 /**
1317 * @tc.number: SUB_Service_HandleExceptionOnAppendBundles_0100
1318 * @tc.name: SUB_Service_HandleExceptionOnAppendBundles_0100
1319 * @tc.desc: 测试 HandleExceptionOnAppendBundles 接口
1320 * @tc.size: MEDIUM
1321 * @tc.type: FUNC
1322 * @tc.level Level 1
1323 * @tc.require: I8ZIMJ
1324 */
1325 HWTEST_F(ServiceTest, SUB_Service_HandleExceptionOnAppendBundles_0100, testing::ext::TestSize.Level1)
1326 {
1327 GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_HandleExceptionOnAppendBundles_0100";
1328 try {
1329 int32_t saID = 4801;
1330 wptr<Service> reversePtr(new Service(saID));
1331 sptr<SvcSessionManager> session(new SvcSessionManager(reversePtr));
1332 vector<BundleName> appendBundleNames {"123456"};
1333 vector<BundleName> restoreBundleNames {"abcdef"};
1334 EXPECT_TRUE(servicePtr_ != nullptr);
1335 servicePtr_->HandleExceptionOnAppendBundles(session, appendBundleNames, restoreBundleNames);
1336
1337 appendBundleNames.push_back("789");
1338 servicePtr_->HandleExceptionOnAppendBundles(session, appendBundleNames, restoreBundleNames);
1339
1340 restoreBundleNames.push_back("123456");
1341 restoreBundleNames.push_back("123");
1342 servicePtr_->HandleExceptionOnAppendBundles(session, appendBundleNames, restoreBundleNames);
1343 } catch (...) {
1344 EXPECT_TRUE(false);
1345 GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by HandleExceptionOnAppendBundles.";
1346 }
1347 GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_HandleExceptionOnAppendBundles_0100";
1348 }
1349
1350 /**
1351 * @tc.number: SUB_Service_SetCurrentSessProperties_0100
1352 * @tc.name: SUB_Service_SetCurrentSessProperties_0100
1353 * @tc.desc: 测试 SetCurrentSessProperties 接口
1354 * @tc.size: MEDIUM
1355 * @tc.type: FUNC
1356 * @tc.level Level 1
1357 * @tc.require: I8ZIMJ
1358 */
1359 HWTEST_F(ServiceTest, SUB_Service_SetCurrentSessProperties_0100, testing::ext::TestSize.Level1)
1360 {
1361 GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_SetCurrentSessProperties_0100";
1362 try {
1363 BJsonEntityCaps::BundleInfo aInfo {};
1364 aInfo.name = "123456";
1365 aInfo.extensionName = "abcdef";
1366 aInfo.allToBackup = true;
1367 std::vector<BJsonEntityCaps::BundleInfo> restoreBundleInfos {aInfo};
1368 std::vector<std::string> restoreBundleNames {"12345678"};
1369 RestoreTypeEnum restoreType = RESTORE_DATA_READDY;
1370 std::string backupVersion;
1371 EXPECT_TRUE(servicePtr_ != nullptr);
1372 servicePtr_->session_ = sptr(new SvcSessionManager(servicePtr_));
1373 servicePtr_->SetCurrentSessProperties(restoreBundleInfos, restoreBundleNames, restoreType, backupVersion);
1374
1375 restoreBundleNames.push_back("123456");
1376 servicePtr_->SetCurrentSessProperties(restoreBundleInfos, restoreBundleNames, restoreType, backupVersion);
1377
1378 restoreBundleInfos.clear();
1379 aInfo.allToBackup = true;
1380 aInfo.versionName = "0.0.0.0-0.0.0.0";
1381 aInfo.extensionName = "";
1382 restoreBundleInfos.push_back(aInfo);
1383 servicePtr_->SetCurrentSessProperties(restoreBundleInfos, restoreBundleNames, restoreType, backupVersion);
1384
1385 restoreBundleInfos.clear();
1386 aInfo.name = "123456a";
1387 restoreBundleInfos.push_back(aInfo);
1388 restoreBundleNames.push_back("123456a");
1389 servicePtr_->SetCurrentSessProperties(restoreBundleInfos, restoreBundleNames, restoreType, backupVersion);
1390
1391 restoreBundleInfos.clear();
1392 aInfo.allToBackup = false;
1393 aInfo.extensionName = "";
1394 restoreBundleInfos.push_back(aInfo);
1395 servicePtr_->SetCurrentSessProperties(restoreBundleInfos, restoreBundleNames, restoreType, backupVersion);
1396
1397 restoreBundleInfos.clear();
1398 aInfo.allToBackup = false;
1399 aInfo.extensionName = "";
1400 restoreBundleInfos.push_back(aInfo);
1401 servicePtr_->SetCurrentSessProperties(restoreBundleInfos, restoreBundleNames, restoreType, backupVersion);
1402 } catch (...) {
1403 EXPECT_TRUE(true);
1404 GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by SetCurrentSessProperties.";
1405 }
1406 GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_SetCurrentSessProperties_0100";
1407 }
1408
1409 /**
1410 * @tc.number: SUB_Service_SetCurrentSessProperties_0101
1411 * @tc.name: SUB_Service_SetCurrentSessProperties_0101
1412 * @tc.desc: 测试 SetCurrentSessProperties 接口
1413 * @tc.size: MEDIUM
1414 * @tc.type: FUNC
1415 * @tc.level Level 1
1416 * @tc.require: I8ZIMJ
1417 */
1418 HWTEST_F(ServiceTest, SUB_Service_SetCurrentSessProperties_0101, testing::ext::TestSize.Level1)
1419 {
1420 GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_SetCurrentSessProperties_0101";
1421 try {
1422 BJsonEntityCaps::BundleInfo aInfo {};
1423 aInfo.name = "123456";
1424 aInfo.versionName = "0.0.0.0-0.0.0.0";
1425 aInfo.extensionName = "abcdef";
1426 aInfo.allToBackup = false;
1427 std::vector<BJsonEntityCaps::BundleInfo> restoreBundleInfos {aInfo};
1428 std::vector<std::string> restoreBundleNames {"123456"};
1429 RestoreTypeEnum restoreType = RESTORE_DATA_READDY;
1430 std::string backupVersion;
1431 EXPECT_TRUE(servicePtr_ != nullptr);
1432 servicePtr_->session_ = sptr(new SvcSessionManager(servicePtr_));
1433 servicePtr_->SetCurrentSessProperties(restoreBundleInfos, restoreBundleNames, restoreType, backupVersion);
1434
1435 restoreBundleInfos.clear();
1436 aInfo.extensionName = "";
1437 restoreBundleInfos.push_back(aInfo);
1438 servicePtr_->SetCurrentSessProperties(restoreBundleInfos, restoreBundleNames, restoreType, backupVersion);
1439
1440 restoreBundleInfos.clear();
1441 aInfo.name = "123456a";
1442 restoreBundleInfos.push_back(aInfo);
1443 restoreBundleNames.push_back("123456a");
1444 servicePtr_->SetCurrentSessProperties(restoreBundleInfos, restoreBundleNames, restoreType, backupVersion);
1445 } catch (...) {
1446 EXPECT_TRUE(false);
1447 GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by SetCurrentSessProperties.";
1448 }
1449 GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_SetCurrentSessProperties_0101";
1450 }
1451
1452 /**
1453 * @tc.number: SUB_Service_SetCurrentSessProperties_0102
1454 * @tc.name: SUB_Service_SetCurrentSessProperties_0102
1455 * @tc.desc: 测试 SetCurrentSessProperties 接口
1456 * @tc.size: MEDIUM
1457 * @tc.type: FUNC
1458 * @tc.level Level 1
1459 * @tc.require: I8ZIMJ
1460 */
1461 HWTEST_F(ServiceTest, SUB_Service_SetCurrentSessProperties_0102, testing::ext::TestSize.Level1)
1462 {
1463 GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_SetCurrentSessProperties_0102";
1464 try {
1465 BJsonEntityCaps::BundleInfo aInfo {};
1466 aInfo.name = "123456";
1467 aInfo.versionName = "0.0.0.0-0.0.0.0";
1468 aInfo.extensionName = "abcdef";
1469 aInfo.allToBackup = false;
1470 std::vector<BJsonEntityCaps::BundleInfo> restoreBundleInfos {aInfo};
1471 std::vector<std::string> restoreBundleNames {"123456"};
1472 RestoreTypeEnum restoreType = RESTORE_DATA_READDY;
1473 std::string backupVersion;
1474 EXPECT_TRUE(servicePtr_ != nullptr);
1475 servicePtr_->SetCurrentSessProperties(restoreBundleInfos, restoreBundleNames, restoreType, backupVersion);
1476
1477 restoreBundleInfos.clear();
1478 aInfo.versionName = "1.1.1.1-1.1.1.1";
1479 aInfo.extensionName = "";
1480 aInfo.name = "123456";
1481 restoreBundleInfos.push_back(aInfo);
1482 servicePtr_->SetCurrentSessProperties(restoreBundleInfos, restoreBundleNames, restoreType, backupVersion);
1483
1484 restoreBundleInfos.clear();
1485 aInfo.name = "123456a";
1486 restoreBundleInfos.push_back(aInfo);
1487 servicePtr_->SetCurrentSessProperties(restoreBundleInfos, restoreBundleNames, restoreType, backupVersion);
1488
1489 restoreBundleInfos.clear();
1490 aInfo.extensionName = "abcdef";
1491 restoreBundleInfos.push_back(aInfo);
1492 servicePtr_->SetCurrentSessProperties(restoreBundleInfos, restoreBundleNames, restoreType, backupVersion);
1493
1494 restoreBundleInfos.clear();
1495 aInfo.name = "123456";
1496 restoreBundleInfos.push_back(aInfo);
1497 servicePtr_->SetCurrentSessProperties(restoreBundleInfos, restoreBundleNames, restoreType, backupVersion);
1498 } catch (...) {
1499 EXPECT_TRUE(true);
1500 GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by SetCurrentSessProperties.";
1501 }
1502 GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_SetCurrentSessProperties_0102";
1503 }
1504
1505 /**
1506 * @tc.number: SUB_Service_AppendBundlesRestoreSession_0100
1507 * @tc.name: SUB_Service_AppendBundlesRestoreSession_0100
1508 * @tc.desc: 测试 AppendBundlesRestoreSession 接口
1509 * @tc.size: MEDIUM
1510 * @tc.type: FUNC
1511 * @tc.level Level 1
1512 * @tc.require: I8ZIMJ
1513 */
1514 HWTEST_F(ServiceTest, SUB_Service_AppendBundlesRestoreSession_0100, testing::ext::TestSize.Level1)
1515 {
1516 GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_AppendBundlesRestoreSession_0100";
1517 try {
1518 UniqueFd fd = servicePtr_->GetLocalCapabilities();
1519 EXPECT_GE(fd, BError(BError::Codes::OK));
1520 vector<BundleName> bundleNames {};
1521 RestoreTypeEnum restoreType = RESTORE_DATA_READDY;
1522 int32_t userId = 1;
1523 EXPECT_TRUE(servicePtr_ != nullptr);
1524 auto ret = servicePtr_->AppendBundlesRestoreSession(move(fd), bundleNames, restoreType, userId);
1525 EXPECT_EQ(ret, BError(BError::Codes::OK));
1526 } catch (...) {
1527 EXPECT_TRUE(false);
1528 GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by AppendBundlesRestoreSession.";
1529 }
1530 GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_AppendBundlesRestoreSession_0100";
1531 }
1532
1533 /**
1534 * @tc.number: SUB_Service_HandleCurBundleEndWork_0100
1535 * @tc.name: SUB_Service_HandleCurBundleEndWork_0100
1536 * @tc.desc: 测试 HandleCurBundleEndWork 接口
1537 * @tc.size: MEDIUM
1538 * @tc.type: FUNC
1539 * @tc.level Level 1
1540 * @tc.require: I8ZIMJ
1541 */
1542 HWTEST_F(ServiceTest, SUB_Service_HandleCurBundleEndWork_0100, testing::ext::TestSize.Level1)
1543 {
1544 GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_HandleCurBundleEndWork_0100";
1545 try {
1546 SvcSessionManager::Impl impl_;
1547 impl_.clientToken = 1;
1548 BackupExtInfo extInfo {};
1549 extInfo.backUpConnection = nullptr;
1550 impl_.backupExtNameMap[BUNDLE_NAME] = extInfo;
1551 impl_.scenario = IServiceReverse::Scenario::RESTORE;
1552 EXPECT_TRUE(servicePtr_ != nullptr);
1553 servicePtr_->HandleCurBundleEndWork(BUNDLE_NAME, BackupRestoreScenario::FULL_RESTORE);
1554 } catch (...) {
1555 EXPECT_TRUE(false);
1556 GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by HandleCurBundleEndWork.";
1557 }
1558 GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_HandleCurBundleEndWork_0100";
1559 }
1560
1561 /**
1562 * @tc.number: SUB_Service_LaunchBackupSAExtension_0100
1563 * @tc.name: SUB_Service_LaunchBackupSAExtension_0100
1564 * @tc.desc: 测试 LaunchBackupSAExtension 接口
1565 * @tc.size: MEDIUM
1566 * @tc.type: FUNC
1567 * @tc.level Level 1
1568 * @tc.require: I8ZIMJ
1569 */
1570 HWTEST_F(ServiceTest, SUB_Service_LaunchBackupSAExtension_0100, testing::ext::TestSize.Level1)
1571 {
1572 GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_LaunchBackupSAExtension_0100";
1573 try {
1574 std::string bundleName = "123456";
1575 ErrCode ret = Init(IServiceReverse::Scenario::RESTORE);
1576 EXPECT_EQ(ret, BError(BError::Codes::OK));
1577 EXPECT_TRUE(servicePtr_ != nullptr);
1578 ret = servicePtr_->LaunchBackupSAExtension(BUNDLE_NAME);
1579 EXPECT_EQ(ret, BError(BError::Codes::OK));
1580
1581 SvcSessionManager::Impl impl_;
1582 impl_.clientToken = 1;
1583 BackupExtInfo extInfo {};
1584 extInfo.backUpConnection = nullptr;
1585
__anon858d7f470602(const string &&bundleName) 1586 auto callDied = [](const string &&bundleName) {};
__anon858d7f470702(const string &&bundleName) 1587 auto callConnected = [](const string &&bundleName) {};
1588 auto callBackup = [](const std::string &&bundleName, const int &&fd, const std::string &&result,
__anon858d7f470802(const std::string &&bundleName, const int &&fd, const std::string &&result, const ErrCode &&errCode) 1589 const ErrCode &&errCode) {};
__anon858d7f470902(const std::string &&bundleName, const std::string &&result, const ErrCode &&errCode) 1590 auto callRestore = [](const std::string &&bundleName, const std::string &&result, const ErrCode &&errCode) {};
1591 extInfo.saBackupConnection =
1592 std::make_shared<SABackupConnection>(callDied, callConnected, callBackup, callRestore);
1593
1594 impl_.backupExtNameMap[BUNDLE_NAME] = extInfo;
1595 ret = servicePtr_->LaunchBackupSAExtension(bundleName);
1596 EXPECT_NE(ret, BError(BError::Codes::OK));
1597
1598 ret = Init(IServiceReverse::Scenario::BACKUP);
1599 EXPECT_EQ(ret, BError(BError::Codes::OK));
1600 ret = servicePtr_->LaunchBackupSAExtension(bundleName);
1601 EXPECT_NE(ret, BError(BError::Codes::OK));
1602 } catch (...) {
1603 EXPECT_TRUE(false);
1604 GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by LaunchBackupSAExtension.";
1605 }
1606 GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_LaunchBackupSAExtension_0100";
1607 }
1608
1609 /**
1610 * @tc.number: SUB_Service_ExtConnectDied_0100
1611 * @tc.name: SUB_Service_ExtConnectDied_0100
1612 * @tc.desc: 测试 ExtConnectDied 接口
1613 * @tc.size: MEDIUM
1614 * @tc.type: FUNC
1615 * @tc.level Level 1
1616 * @tc.require: I8ZIMJ
1617 */
1618 HWTEST_F(ServiceTest, SUB_Service_ExtConnectDied_0100, testing::ext::TestSize.Level1)
1619 {
1620 GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_ExtConnectDied_0100";
1621 try {
1622 std::string callName = "123456";
1623 ErrCode ret = Init(IServiceReverse::Scenario::RESTORE);
1624 EXPECT_EQ(ret, BError(BError::Codes::OK));
1625 SvcSessionManager::Impl impl_;
1626 impl_.clientToken = 1;
1627 BackupExtInfo extInfo {};
__anon858d7f470a02(const string &&bundleName, bool isCleanCalled) 1628 auto callDied = [](const string &&bundleName, bool isCleanCalled) {};
__anon858d7f470b02(const string &&bundleName) 1629 auto callConnected = [](const string &&bundleName) {};
1630 string bundleNameIndexInfo = "123456789";
1631 extInfo.backUpConnection = sptr(new SvcBackupConnection(callDied, callConnected, bundleNameIndexInfo));
1632 impl_.backupExtNameMap[BUNDLE_NAME] = extInfo;
1633 impl_.scenario = IServiceReverse::Scenario::RESTORE;
1634 EXPECT_TRUE(servicePtr_ != nullptr);
1635 servicePtr_->ExtConnectDied(callName);
1636 extInfo.backUpConnection->isConnected_.store(true);
1637 servicePtr_->ExtConnectDied(callName);
1638 } catch (...) {
1639 EXPECT_TRUE(false);
1640 GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by ExtConnectDied.";
1641 }
1642 GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_ExtConnectDied_0100";
1643 }
1644
1645 /**
1646 * @tc.number: SUB_Service_NoticeClientFinish_0100
1647 * @tc.name: SUB_Service_NoticeClientFinish_0100
1648 * @tc.desc: 测试 NoticeClientFinish 接口
1649 * @tc.size: MEDIUM
1650 * @tc.type: FUNC
1651 * @tc.level Level 1
1652 * @tc.require: I8ZIMJ
1653 */
1654 HWTEST_F(ServiceTest, SUB_Service_NoticeClientFinish_0100, testing::ext::TestSize.Level1)
1655 {
1656 GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_NoticeClientFinish_0100";
1657 try {
1658 ErrCode ret = Init(IServiceReverse::Scenario::RESTORE);
1659 EXPECT_EQ(ret, BError(BError::Codes::OK));
1660 EXPECT_TRUE(servicePtr_ != nullptr);
1661 servicePtr_->NoticeClientFinish(BUNDLE_NAME, BError(BError::Codes::OK));
1662 GTEST_LOG_(INFO) << "SUB_Service_NoticeClientFinish_0100 BACKUP";
1663 ret = Init(IServiceReverse::Scenario::BACKUP);
1664 EXPECT_EQ(ret, BError(BError::Codes::OK));
1665 servicePtr_->NoticeClientFinish(BUNDLE_NAME, BError(BError::Codes::OK));
1666
1667 SvcSessionManager::Impl impl_;
1668 impl_.clientToken = 1;
1669 impl_.restoreDataType = RESTORE_DATA_READDY;
1670 ret = Init(IServiceReverse::Scenario::RESTORE);
1671 EXPECT_EQ(ret, BError(BError::Codes::OK));
1672 servicePtr_->NoticeClientFinish(BUNDLE_NAME, BError(BError::Codes::OK));
1673 } catch (...) {
1674 EXPECT_TRUE(false);
1675 GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by NoticeClientFinish.";
1676 }
1677 GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_NoticeClientFinish_0100";
1678 }
1679
1680 /**
1681 * @tc.number: SUB_Service_OnAllBundlesFinished_0100
1682 * @tc.name: SUB_Service_OnAllBundlesFinished_0100
1683 * @tc.desc: 测试 OnAllBundlesFinished 接口
1684 * @tc.size: MEDIUM
1685 * @tc.type: FUNC
1686 * @tc.level Level 1
1687 * @tc.require: I6F3GV
1688 */
1689 HWTEST_F(ServiceTest, SUB_Service_OnAllBundlesFinished_0100, testing::ext::TestSize.Level1)
1690 {
1691 GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_OnAllBundlesFinished_0100";
1692 try {
1693 ErrCode ret = Init(IServiceReverse::Scenario::BACKUP);
1694 EXPECT_EQ(ret, BError(BError::Codes::OK));
1695 EXPECT_TRUE(servicePtr_ != nullptr);
1696 servicePtr_->session_ = sptr(new SvcSessionManager(servicePtr_));
1697 servicePtr_->OnAllBundlesFinished(BError(BError::Codes::OK));
1698
1699 ret = Init(IServiceReverse::Scenario::RESTORE);
1700 EXPECT_EQ(ret, BError(BError::Codes::OK));
1701 servicePtr_->OnAllBundlesFinished(BError(BError::Codes::OK));
1702 } catch (...) {
1703 EXPECT_TRUE(false);
1704 GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by OnAllBundlesFinished.";
1705 }
1706 GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_OnAllBundlesFinished_0100";
1707 }
1708
1709 /**
1710 * @tc.number: SUB_Service_SendEndAppGalleryNotify_0100
1711 * @tc.name: SUB_Service_SendEndAppGalleryNotify_0100
1712 * @tc.desc: 测试 SendEndAppGalleryNotify 接口
1713 * @tc.size: MEDIUM
1714 * @tc.type: FUNC
1715 * @tc.level Level 1
1716 * @tc.require: I8ZIMJ
1717 */
1718 HWTEST_F(ServiceTest, SUB_Service_SendEndAppGalleryNotify_0100, testing::ext::TestSize.Level1)
1719 {
1720 GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_SendEndAppGalleryNotify_0100";
1721 try {
1722 ErrCode ret = Init(IServiceReverse::Scenario::BACKUP);
1723 EXPECT_EQ(ret, BError(BError::Codes::OK));
1724 EXPECT_TRUE(servicePtr_ != nullptr);
1725 servicePtr_->SendEndAppGalleryNotify(BUNDLE_NAME);
1726
1727 ret = Init(IServiceReverse::Scenario::RESTORE);
1728 EXPECT_EQ(ret, BError(BError::Codes::OK));
1729 servicePtr_->SendEndAppGalleryNotify(BUNDLE_NAME);
1730 } catch (...) {
1731 EXPECT_TRUE(false);
1732 GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by SendEndAppGalleryNotify.";
1733 }
1734 GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_SendEndAppGalleryNotify_0100";
1735 }
1736
1737 /**
1738 * @tc.number: SUB_Service_SendErrAppGalleryNotify_0100
1739 * @tc.name: SUB_Service_SendErrAppGalleryNotify_0100
1740 * @tc.desc: 测试 SendErrAppGalleryNotify 接口
1741 * @tc.size: MEDIUM
1742 * @tc.type: FUNC
1743 * @tc.level Level 1
1744 * @tc.require: I8ZIMJ
1745 */
1746 HWTEST_F(ServiceTest, SUB_Service_SendErrAppGalleryNotify_0100, testing::ext::TestSize.Level1)
1747 {
1748 GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_SendErrAppGalleryNotify_0100";
1749 try {
1750 ErrCode ret = Init(IServiceReverse::Scenario::BACKUP);
1751 EXPECT_EQ(ret, BError(BError::Codes::OK));
1752 EXPECT_TRUE(servicePtr_ != nullptr);
1753 servicePtr_->SendErrAppGalleryNotify();
1754
1755 ret = Init(IServiceReverse::Scenario::RESTORE);
1756 EXPECT_EQ(ret, BError(BError::Codes::OK));
1757 servicePtr_->SendErrAppGalleryNotify();
1758 } catch (...) {
1759 EXPECT_TRUE(false);
1760 GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by SendErrAppGalleryNotify.";
1761 }
1762 GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_SendErrAppGalleryNotify_0100";
1763 }
1764
1765 /**
1766 * @tc.number: SUB_Service_ClearDisposalOnSaStart_0100
1767 * @tc.name: SUB_Service_ClearDisposalOnSaStart_0100
1768 * @tc.desc: 测试 ClearDisposalOnSaStart 接口
1769 * @tc.size: MEDIUM
1770 * @tc.type: FUNC
1771 * @tc.level Level 1
1772 * @tc.require: I8ZIMJ
1773 */
1774 HWTEST_F(ServiceTest, SUB_Service_ClearDisposalOnSaStart_0100, testing::ext::TestSize.Level1)
1775 {
1776 GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_ClearDisposalOnSaStart_0100";
1777 try {
1778 ErrCode ret = Init(IServiceReverse::Scenario::BACKUP);
1779 EXPECT_EQ(ret, BError(BError::Codes::OK));
1780 EXPECT_TRUE(servicePtr_ != nullptr);
1781 servicePtr_->ClearDisposalOnSaStart();
1782
1783 ret = Init(IServiceReverse::Scenario::RESTORE);
1784 EXPECT_EQ(ret, BError(BError::Codes::OK));
1785 servicePtr_->ClearDisposalOnSaStart();
1786 } catch (...) {
1787 EXPECT_TRUE(false);
1788 GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by ClearDisposalOnSaStart.";
1789 }
1790 GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_ClearDisposalOnSaStart_0100";
1791 }
1792
1793 /**
1794 * @tc.number: SUB_Service_DeleteDisConfigFile_0100
1795 * @tc.name: SUB_Service_DeleteDisConfigFile_0100
1796 * @tc.desc: 测试 DeleteDisConfigFile 接口
1797 * @tc.size: MEDIUM
1798 * @tc.type: FUNC
1799 * @tc.level Level 1
1800 * @tc.require: I8ZIMJ
1801 */
1802 HWTEST_F(ServiceTest, SUB_Service_DeleteDisConfigFile_0100, testing::ext::TestSize.Level1)
1803 {
1804 GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_DeleteDisConfigFile_0100";
1805 try {
1806 ErrCode ret = Init(IServiceReverse::Scenario::BACKUP);
1807 EXPECT_EQ(ret, BError(BError::Codes::OK));
1808 EXPECT_TRUE(servicePtr_ != nullptr);
1809 servicePtr_->DeleteDisConfigFile();
1810
1811 ret = Init(IServiceReverse::Scenario::RESTORE);
1812 EXPECT_EQ(ret, BError(BError::Codes::OK));
1813 servicePtr_->DeleteDisConfigFile();
1814 } catch (...) {
1815 EXPECT_TRUE(false);
1816 GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by DeleteDisConfigFile.";
1817 }
1818 GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_DeleteDisConfigFile_0100";
1819 }
1820
1821 /**
1822 * @tc.number: SUB_Service_ExtensionConnectFailRadarReport_0100
1823 * @tc.name: SUB_Service_ExtensionConnectFailRadarReport_0100
1824 * @tc.desc: 测试 ExtensionConnectFailRadarReport 接口
1825 * @tc.size: MEDIUM
1826 * @tc.type: FUNC
1827 * @tc.level Level 1
1828 * @tc.require: I8ZIMJ
1829 */
1830 HWTEST_F(ServiceTest, SUB_Service_ExtensionConnectFailRadarReport_0100, testing::ext::TestSize.Level1)
1831 {
1832 GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_ExtensionConnectFailRadarReport_0100";
1833 try {
1834 ErrCode ret = Init(IServiceReverse::Scenario::BACKUP);
1835 EXPECT_EQ(ret, BError(BError::Codes::OK));
1836 EXPECT_TRUE(servicePtr_ != nullptr);
1837 servicePtr_->ClearBundleRadarReport();
1838 servicePtr_->ExtensionConnectFailRadarReport(BUNDLE_NAME, BError(BError::Codes::OK),
1839 IServiceReverse::Scenario::BACKUP);
1840 EXPECT_TRUE(true);
1841
1842 ret = Init(IServiceReverse::Scenario::RESTORE);
1843 EXPECT_EQ(ret, BError(BError::Codes::OK));
1844 servicePtr_->ExtensionConnectFailRadarReport(BUNDLE_NAME, BError(BError::Codes::OK),
1845 IServiceReverse::Scenario::RESTORE);
1846 EXPECT_TRUE(true);
1847 } catch (...) {
1848 EXPECT_TRUE(false);
1849 GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by ExtensionConnectFailRadarReport.";
1850 }
1851 GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_ExtensionConnectFailRadarReport_0100";
1852 }
1853
1854 /**
1855 * @tc.number: SUB_Service_StartRunningTimer_0100
1856 * @tc.name: SUB_Service_StartRunningTimer_0100
1857 * @tc.desc: 测试 StartRunningTimer 接口
1858 * @tc.size: MEDIUM
1859 * @tc.type: FUNC
1860 * @tc.level Level 1
1861 * @tc.require: I8ZIMJ
1862 */
1863 HWTEST_F(ServiceTest, SUB_Service_StartRunningTimer_0100, testing::ext::TestSize.Level1)
1864 {
1865 GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_StartRunningTimer_0100";
1866 try {
1867 ErrCode ret = Init(IServiceReverse::Scenario::BACKUP);
1868 EXPECT_EQ(ret, BError(BError::Codes::OK));
1869 EXPECT_TRUE(servicePtr_ != nullptr);
1870 servicePtr_->StartRunningTimer(BUNDLE_NAME);
1871 EXPECT_TRUE(true);
1872
1873 ret = Init(IServiceReverse::Scenario::RESTORE);
1874 EXPECT_EQ(ret, BError(BError::Codes::OK));
1875 servicePtr_->StartRunningTimer(BUNDLE_NAME);
1876 EXPECT_TRUE(true);
1877 } catch (...) {
1878 EXPECT_TRUE(false);
1879 GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by StartRunningTimer.";
1880 }
1881 GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_StartRunningTimer_0100";
1882 }
1883
1884 /**
1885 * @tc.number: SUB_Service_TimeoutRadarReport_0100
1886 * @tc.name: SUB_Service_TimeoutRadarReport_0100
1887 * @tc.desc: 测试 TimeoutRadarReport 接口
1888 * @tc.size: MEDIUM
1889 * @tc.type: FUNC
1890 * @tc.level Level 1
1891 * @tc.require: I8ZIMJ
1892 */
1893 HWTEST_F(ServiceTest, SUB_Service_TimeoutRadarReport_0100, testing::ext::TestSize.Level1)
1894 {
1895 GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_TimeoutRadarReport_0100";
1896 try {
1897 ErrCode ret = Init(IServiceReverse::Scenario::BACKUP);
1898 EXPECT_EQ(ret, BError(BError::Codes::OK));
1899 EXPECT_TRUE(servicePtr_ != nullptr);
1900 std::string bundleName = BUNDLE_NAME;
1901 servicePtr_->ClearBundleRadarReport();
1902 servicePtr_->TimeoutRadarReport(IServiceReverse::Scenario::BACKUP, bundleName);
1903 EXPECT_TRUE(true);
1904
1905 ret = Init(IServiceReverse::Scenario::RESTORE);
1906 EXPECT_EQ(ret, BError(BError::Codes::OK));
1907 servicePtr_->TimeoutRadarReport(IServiceReverse::Scenario::RESTORE, bundleName);
1908 EXPECT_TRUE(true);
1909 } catch (...) {
1910 EXPECT_TRUE(false);
1911 GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by TimeoutRadarReport.";
1912 }
1913 GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_TimeoutRadarReport_0100";
1914 }
1915
1916 /**
1917 * @tc.number: SUB_Service_ReportOnBundleStarted_0100
1918 * @tc.name: SUB_Service_ReportOnBundleStarted_0100
1919 * @tc.desc: 测试 ReportOnBundleStarted 接口
1920 * @tc.size: MEDIUM
1921 * @tc.type: FUNC
1922 * @tc.level Level 1
1923 * @tc.require: I8ZIMJ
1924 */
1925 HWTEST_F(ServiceTest, SUB_Service_ReportOnBundleStarted_0100, testing::ext::TestSize.Level1)
1926 {
1927 GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_ReportOnBundleStarted_0100";
1928 try {
1929 ErrCode ret = Init(IServiceReverse::Scenario::BACKUP);
1930 EXPECT_EQ(ret, BError(BError::Codes::OK));
1931 EXPECT_TRUE(servicePtr_ != nullptr);
1932 servicePtr_->ReportOnBundleStarted(IServiceReverse::Scenario::BACKUP, BUNDLE_NAME);
1933 EXPECT_TRUE(true);
1934
1935 ret = Init(IServiceReverse::Scenario::RESTORE);
1936 EXPECT_EQ(ret, BError(BError::Codes::OK));
1937 servicePtr_->ReportOnBundleStarted(IServiceReverse::Scenario::RESTORE, BUNDLE_NAME);
1938 EXPECT_TRUE(true);
1939 } catch (...) {
1940 EXPECT_TRUE(false);
1941 GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by ReportOnBundleStarted.";
1942 }
1943 GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_ReportOnBundleStarted_0100";
1944 }
1945
1946 /**
1947 * @tc.number: SUB_Service_HandleNotSupportBundleNames_0100
1948 * @tc.name: SUB_Service_HandleNotSupportBundleNames_0100
1949 * @tc.desc: 测试 HandleNotSupportBundleNames 接口
1950 * @tc.size: MEDIUM
1951 * @tc.type: FUNC
1952 * @tc.level Level 1
1953 * @tc.require: I8ZIMJ
1954 */
1955 HWTEST_F(ServiceTest, SUB_Service_HandleNotSupportBundleNames_0100, testing::ext::TestSize.Level1)
1956 {
1957 GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_HandleNotSupportBundleNames_0100";
1958 try {
1959 ErrCode ret = Init(IServiceReverse::Scenario::BACKUP);
1960 EXPECT_EQ(ret, BError(BError::Codes::OK));
1961 EXPECT_TRUE(servicePtr_ != nullptr);
1962 const std::vector<std::string> srcBundleNames = {"test0", "test1", "test2", "test3"};
1963 std::vector<std::string> supportBundleNames = {"test2", "test3", "test4", "test5"};
1964
1965 servicePtr_->HandleNotSupportBundleNames(srcBundleNames, supportBundleNames, false);
1966 EXPECT_TRUE(true);
1967 servicePtr_->HandleNotSupportBundleNames(srcBundleNames, supportBundleNames, true);
1968 EXPECT_TRUE(true);
1969 } catch (...) {
1970 EXPECT_TRUE(false);
1971 GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by HandleNotSupportBundleNames.";
1972 }
1973 GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_HandleNotSupportBundleNames_0100";
1974 }
1975
1976 /**
1977 * @tc.number: SUB_Service_RefreshDataSize_0100
1978 * @tc.name: SUB_Service_RefreshDataSize_0100
1979 * @tc.desc: 测试 RefreshDataSize 接口
1980 * @tc.size: MEDIUM
1981 * @tc.type: FUNC
1982 * @tc.level Level 1
1983 * @tc.require: I6F3GV
1984 */
1985 HWTEST_F(ServiceTest, SUB_Service_RefreshDataSize_0100, testing::ext::TestSize.Level1)
1986 {
1987 GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_RefreshDataSize_0100";
1988 try {
1989 string fileName = MANAGE_JSON;
1990 EXPECT_TRUE(servicePtr_ != nullptr);
1991 servicePtr_->session_ = nullptr;
1992 auto ret = servicePtr_->RefreshDataSize(0);
1993 EXPECT_EQ(ret, BError(BError::Codes::SA_INVAL_ARG));
1994
1995 servicePtr_->session_ = sptr(new SvcSessionManager(servicePtr_));
1996 ret = servicePtr_->RefreshDataSize(0);
1997 EXPECT_EQ(ret, BError(BError::Codes::OK));
1998 } catch (...) {
1999 EXPECT_TRUE(false);
2000 GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by RefreshDataSize.";
2001 }
2002 GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_RefreshDataSize_0100";
2003 }
2004
2005 /**
2006 * @tc.number: SUB_Service_StopExtTimer_0100
2007 * @tc.name: SUB_Service_StopExtTimer_0100
2008 * @tc.desc: 测试 StopExtTimer 接口
2009 * @tc.size: MEDIUM
2010 * @tc.type: FUNC
2011 * @tc.level Level 1
2012 * @tc.require: I6F3GV
2013 */
2014 HWTEST_F(ServiceTest, SUB_Service_StopExtTimer_0100, testing::ext::TestSize.Level1)
2015 {
2016 GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_StopExtTimer_0100";
2017 try {
2018 string fileName = MANAGE_JSON;
2019 EXPECT_TRUE(servicePtr_ != nullptr);
2020 servicePtr_->session_ = nullptr;
2021 bool isExtStop = false;
2022
2023 auto ret = servicePtr_->StopExtTimer(isExtStop);
2024 EXPECT_EQ(ret, BError(BError::Codes::SA_INVAL_ARG));
2025
2026 servicePtr_->session_ = sptr(new SvcSessionManager(servicePtr_));
2027 ret = servicePtr_->StopExtTimer(isExtStop);
2028 EXPECT_EQ(ret, BError(BError::Codes::OK));
2029 } catch (...) {
2030 EXPECT_TRUE(false);
2031 GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by StopExtTimer.";
2032 }
2033 GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_StopExtTimer_0100";
2034 }
2035
2036 /**
2037 * @tc.number: SUB_Service_PublishFile_0103
2038 * @tc.name: SUB_Service_PublishFile_0103
2039 * @tc.desc: 测试 PublishFile 接口
2040 * @tc.size: MEDIUM
2041 * @tc.type: FUNC
2042 * @tc.level Level 1
2043 * @tc.require: I6F3GV
2044 */
2045 HWTEST_F(ServiceTest, SUB_Service_PublishFile_0103, testing::ext::TestSize.Level1)
2046 {
2047 GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_PublishFile_0103";
2048 try {
2049 ErrCode ret = Init(IServiceReverse::Scenario::RESTORE);
2050 EXPECT_EQ(ret, BError(BError::Codes::OK));
2051 BFileInfo fileInfo {BUNDLE_NAME, "", 0};
2052 EXPECT_TRUE(servicePtr_ != nullptr);
2053 servicePtr_->session_ = nullptr;
2054 ret = servicePtr_->PublishFile(fileInfo);
2055 EXPECT_EQ(ret, BError(BError::Codes::SA_INVAL_ARG));
2056 servicePtr_->session_ = sptr(new SvcSessionManager(servicePtr_));
2057 } catch (...) {
2058 EXPECT_TRUE(false);
2059 GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by PublishFile.";
2060 }
2061 GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_PublishFile_0103";
2062 }
2063
2064 /**
2065 * @tc.number: SUB_Service_AppFileReady_0104
2066 * @tc.name: SUB_Service_AppFileReady_0104
2067 * @tc.desc: 测试 AppFileReady 接口
2068 * @tc.size: MEDIUM
2069 * @tc.type: FUNC
2070 * @tc.level Level 1
2071 * @tc.require: I6F3GV
2072 */
2073 HWTEST_F(ServiceTest, SUB_Service_AppFileReady_0104, testing::ext::TestSize.Level1)
2074 {
2075 GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_AppFileReady_0104";
2076 try {
2077 string fileName = "manage.json";
2078 EXPECT_TRUE(servicePtr_ != nullptr);
2079 servicePtr_->session_ = nullptr;
2080 auto ret = servicePtr_->AppFileReady(fileName, UniqueFd(-1), 0);
2081 EXPECT_EQ(ret, BError(BError::Codes::SA_INVAL_ARG));
2082 servicePtr_->session_ = sptr(new SvcSessionManager(servicePtr_));
2083 } catch (...) {
2084 EXPECT_TRUE(false);
2085 GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by AppFileReady.";
2086 }
2087 GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_AppFileReady_0104";
2088 }
2089 } // namespace OHOS::FileManagement::Backup