1 /*
2 * Copyright (c) 2023 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 #include <gtest/gtest.h>
16 #include <gmock/gmock.h>
17 #include "native_child_process.h"
18 #include "app_utils.h"
19
20 namespace OHOS {
21 namespace AbilityRuntime {
22
23 using namespace testing;
24 using namespace testing::ext;
25
26 class ChildProcessCapiTest : public testing::Test {
27 public:
28 static void SetUpTestCase(void);
29 static void TearDownTestCase(void);
30
31 static void OnNativeChildProcessStarted(int errCode, OHIPCRemoteProxy *remoteProxy);
32
33 void SetUp();
34 void TearDown();
35 };
36
SetUpTestCase(void)37 void ChildProcessCapiTest::SetUpTestCase(void)
38 {}
39
TearDownTestCase(void)40 void ChildProcessCapiTest::TearDownTestCase(void)
41 {}
42
SetUp(void)43 void ChildProcessCapiTest::SetUp(void)
44 {}
45
TearDown(void)46 void ChildProcessCapiTest::TearDown(void)
47 {}
48
OnNativeChildProcessStarted(int errCode,OHIPCRemoteProxy * remoteProxy)49 void ChildProcessCapiTest::OnNativeChildProcessStarted(int errCode, OHIPCRemoteProxy *remoteProxy)
50 {
51 }
52
53 /**
54 * @tc.number: OH_Ability_CreateNativeChildProcess_001
55 * @tc.desc: Test API OH_Ability_CreateNativeChildProcess works
56 * @tc.type: FUNC
57 */
58 HWTEST_F(ChildProcessCapiTest, OH_Ability_CreateNativeChildProcess_001, TestSize.Level0)
59 {
60 GTEST_LOG_(INFO) << "OH_Ability_CreateNativeChildProcess_001 begin";
61 int ret = OH_Ability_CreateNativeChildProcess(nullptr, ChildProcessCapiTest::OnNativeChildProcessStarted);
62 EXPECT_EQ(ret, NCP_ERR_INVALID_PARAM);
63
64 ret = OH_Ability_CreateNativeChildProcess("test.so", nullptr);
65 EXPECT_EQ(ret, NCP_ERR_INVALID_PARAM);
66
67 ret = OH_Ability_CreateNativeChildProcess("test.so", ChildProcessCapiTest::OnNativeChildProcessStarted);
68 if (!AAFwk::AppUtils::GetInstance().IsMultiProcessModel()) {
69 EXPECT_EQ(ret, NCP_ERR_SERVICE_ERROR);
70 return;
71 } else if (!AAFwk::AppUtils::GetInstance().IsSupportNativeChildProcess()) {
72 EXPECT_EQ(ret, NCP_ERR_MULTI_PROCESS_DISABLED);
73 return;
74 }
75
76 GTEST_LOG_(INFO) << "OH_Ability_CreateNativeChildProcess return " << ret;
77 EXPECT_NE(ret, NCP_ERR_NOT_SUPPORTED);
78 }
79
80 } // namespace AbilityRuntime
81 } // namespace OHOS
82