• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <gtest/gtest.h>
17 
18 #define private public
19 #include "native_child_ipc_process.h"
20 #undef private
21 #include "hilog_tag_wrapper.h"
22 #include "runtime.h"
23 #include "mock_bundle_manager.h"
24 #include "mock_app_mgr_service.h"
25 #include "if_system_ability_manager.h"
26 #include "iservice_registry.h"
27 using namespace testing;
28 using namespace testing::ext;
29 
30 namespace OHOS {
31 namespace AbilityRuntime {
32 class NativeChildIpcProcessTest : public testing::Test {
33 public:
34     static void SetUpTestCase();
35     static void TearDownTestCase();
36     void SetUp() override;
37     void TearDown() override;
38 };
39 
SetUpTestCase()40 void NativeChildIpcProcessTest::SetUpTestCase()
41 {}
42 
TearDownTestCase()43 void NativeChildIpcProcessTest::TearDownTestCase()
44 {}
45 
SetUp()46 void NativeChildIpcProcessTest::SetUp()
47 {}
48 
TearDown()49 void NativeChildIpcProcessTest::TearDown()
50 {}
51 
52 /**
53  * @tc.number: Init_0100
54  * @tc.desc: Test NativeChildIpcProcessTest works
55  * @tc.type: FUNC
56  */
57 HWTEST_F(NativeChildIpcProcessTest, Init_0100, TestSize.Level0)
58 {
59     TAG_LOGD(AAFwkTag::TEST, "Init_0100 called.");
60     auto childProcess = NativeChildIpcProcess::Create();
61     EXPECT_TRUE(childProcess != nullptr);
62     auto ret = childProcess->Init(nullptr);
63     EXPECT_FALSE(ret);
64     TAG_LOGD(AAFwkTag::TEST, "Init_0100 end.");
65 }
66 
67 /**
68  * @tc.number: Init_0200
69  * @tc.desc: Test NativeChildIpcProcessTest works
70  * @tc.type: FUNC
71  */
72 HWTEST_F(NativeChildIpcProcessTest, Init_0200, TestSize.Level0)
73 {
74     TAG_LOGD(AAFwkTag::TEST, "Init_0200 called. start");
75     auto childProcess = NativeChildIpcProcess::Create();
76     EXPECT_TRUE(childProcess != nullptr);
77     std::shared_ptr<ChildProcessStartInfo> info = std::make_shared<ChildProcessStartInfo>();
78     sptr<IRemoteObject> ipcObj = sptr<IRemoteObject>(new (std::nothrow) AppExecFwk::MockAppMgrService());
79     info->ipcObj = ipcObj;
80     auto ret = childProcess->Init(info);
81     EXPECT_FALSE(ret);
82     TAG_LOGD(AAFwkTag::TEST, "Init_0200 called. end");
83 }
84 /**
85  * @tc.number: Init_0300
86  * @tc.desc: Test NativeChildIpcProcessTest works
87  * @tc.type: FUNC
88  */
89 HWTEST_F(NativeChildIpcProcessTest, Init_0300, TestSize.Level0)
90 {
91     TAG_LOGD(AAFwkTag::TEST, "Init_0300 called.");
92     auto childProcess = NativeChildIpcProcess::Create();
93     std::shared_ptr<ChildProcessStartInfo> info = std::make_shared<ChildProcessStartInfo>();
94     OHOS::sptr<OHOS::ISystemAbilityManager> systemAbilityManager =
95     OHOS::SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
96     OHOS::sptr<OHOS::IRemoteObject> ipcObj = systemAbilityManager->GetSystemAbility(501);
97     info->ipcObj = ipcObj;
98     bool ret = childProcess->Init(info);
99     EXPECT_FALSE(ret);
100     TAG_LOGD(AAFwkTag::TEST, "Init_0300 called. end");
101 }
102 
103 /**
104  * @tc.number: Init_0400
105  * @tc.desc: Test NativeChildIpcProcessTest works
106  * @tc.type: FUNC
107  */
108 HWTEST_F(NativeChildIpcProcessTest, Init_0400, TestSize.Level0)
109 {
110     TAG_LOGD(AAFwkTag::TEST, "Init_0400 called.");
111     auto childProcess = NativeChildIpcProcess::Create();
112     std::shared_ptr<ChildProcessStartInfo> info = std::make_shared<ChildProcessStartInfo>();
113     info->name = "AProcess";
114     info->moduleName = "entry";
115     info->srcEntry = "entry/./ets/process/AProcess.ts";
116     info->hapPath = "/data/app/entry-1/base.hap";
117     OHOS::sptr<OHOS::ISystemAbilityManager> systemAbilityManager =
118     OHOS::SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
119     OHOS::sptr<OHOS::IRemoteObject> ipcObj = systemAbilityManager->GetSystemAbility(501);
120     info->ipcObj = ipcObj;
121     bool ret = childProcess->Init(info);
122     EXPECT_FALSE(ret);
123     TAG_LOGD(AAFwkTag::TEST, "Init_0400 end.");
124 }
125 
126 /**
127  * @tc.number: Init_0500
128  * @tc.desc: Test NativeChildIpcProcessTest works
129  * @tc.type: FUNC
130  */
131 HWTEST_F(NativeChildIpcProcessTest, Init_0500, TestSize.Level0)
132 {
133     TAG_LOGD(AAFwkTag::TEST, "Init_0500 called.");
134     auto childProcess = NativeChildIpcProcess::Create();
135     std::shared_ptr<ChildProcessStartInfo> info = std::make_shared<ChildProcessStartInfo>();
136     info->name = "AProcess";
137     info->moduleName = "";
138     info->srcEntry = "entry/./ets/process/AProcess.ts";
139     info->hapPath = "/data/test/hapPath";
140     OHOS::sptr<OHOS::ISystemAbilityManager> systemAbilityManager =
141     OHOS::SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
142     OHOS::sptr<OHOS::IRemoteObject> ipcObjs = systemAbilityManager->GetSystemAbility(501);
143     info->ipcObj = ipcObjs;
144     auto ret = childProcess->Init(info);
145     EXPECT_FALSE(ret);
146     TAG_LOGD(AAFwkTag::TEST, "Init_0500 called. end");
147 }
148 
149 /**
150  * @tc.number: UnloadNativeLib_0100
151  * @tc.desc: Test NativeChildIpcProcessTest works
152  * @tc.type: FUNC
153  */
154 HWTEST_F(NativeChildIpcProcessTest, UnloadNativeLib_0100, TestSize.Level2)
155 {
156     TAG_LOGD(AAFwkTag::TEST, "UnloadNativeLib_0100 called.");
157     auto childProcess = std::make_shared<NativeChildIpcProcess>();
158     childProcess->UnloadNativeLib();
159     EXPECT_EQ(nullptr, childProcess->nativeLibHandle_);
160     TAG_LOGD(AAFwkTag::TEST, "UnloadNativeLib_0100 end.");
161 }
162 } // namespace AbilityRuntime
163 } // namespace OHOS