• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 "sys_installer_ipc_test.h"
17 
18 #include "gtest/gtest.h"
19 #include "if_system_ability_manager.h"
20 #include "iservice_registry.h"
21 #include "isys_installer.h"
22 #include "isys_installer_callback.h"
23 #include "system_ability_definition.h"
24 #include "sys_installer_kits_impl.h"
25 
26 using namespace testing::ext;
27 using namespace std;
28 
29 namespace OHOS {
30 namespace SysInstaller {
SetUpTestCase()31 void SysInstallerIpcUnitTest::SetUpTestCase()
32 {
33     cout << "SysInstallerIpcUnitTest SetUpTestCase" << std::endl;
34 }
35 
TearDownTestCase()36 void SysInstallerIpcUnitTest::TearDownTestCase()
37 {
38     cout << "SysInstallerIpcUnitTest TearDownTestCase" << std::endl;
39 }
40 
SetUp()41 void SysInstallerIpcUnitTest::SetUp()
42 {
43     cout << "SysInstallerIpcUnitTest SetUp" << std::endl;
44 }
45 
TearDown()46 void SysInstallerIpcUnitTest::TearDown()
47 {
48     cout << "SysInstallerIpcUnitTest TearDown" << std::endl;
49 }
50 
51 // init
52 HWTEST_F(SysInstallerIpcUnitTest, SysInstallerInit001, TestSize.Level1)
53 {
54     cout << " SysInstallerInit001 start " << std::endl;
55 
56     auto ret = SysInstallerKitsImpl::GetInstance().SysInstallerInit();
57     ASSERT_EQ(ret, 0);
58 }
59 
60 class ProcessCallbackTest : public ISysInstallerCallbackFunc {
61 public:
62     ProcessCallbackTest() = default;
63     ~ProcessCallbackTest() = default;
OnUpgradeProgress(UpdateStatus updateStatus,int percent,const std::string & resultMsg)64     void OnUpgradeProgress(UpdateStatus updateStatus, int percent, const std::string &resultMsg) override
65     {
66         printf("ProgressCallback progress %d percent %d msg %s\n", updateStatus, percent, resultMsg.c_str());
67     }
68 };
69 
70 // callback
71 HWTEST_F(SysInstallerIpcUnitTest, SetCallBackTest001, TestSize.Level1)
72 {
73     cout << " SetCallBackTest001 start " << std::endl;
74     sptr<ISysInstallerCallbackFunc> callback = new ProcessCallbackTest;
75     auto ret = SysInstallerKitsImpl::GetInstance().SetUpdateCallback(callback);
76     ASSERT_EQ(ret, 0);
77 }
78 
79 // get status
80 HWTEST_F(SysInstallerIpcUnitTest, GetStatusTest001, TestSize.Level1)
81 {
82     cout << " GetStatusTest001 start " << std::endl;
83     auto ret = SysInstallerKitsImpl::GetInstance().GetUpdateStatus();
84     ASSERT_EQ(ret, 0);
85 }
86 
87 // update package
88 HWTEST_F(SysInstallerIpcUnitTest, UpdatePackageTest001, TestSize.Level1)
89 {
90     cout << " UpdatePackageTest001 start " << std::endl;
91     auto ret = SysInstallerKitsImpl::GetInstance().StartUpdatePackageZip(
92         "/data/ota_package/update.zip");
93     cout << " UpdatePackageTest001 ret " << ret << std::endl;
94     ASSERT_EQ(ret, 0);
95 }
96 } // SysInstaller
97 } // OHOS
98