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