• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "child_process_args_manager.h"
20 
21 namespace OHOS {
22 namespace AbilityRuntime {
23 
24 using namespace testing;
25 using namespace testing::ext;
26 
27 class ChildProcessCapiTest : public testing::Test {
28 public:
29     static void SetUpTestCase(void);
30     static void TearDownTestCase(void);
31 
32     static void OnNativeChildProcessStarted(int errCode, OHIPCRemoteProxy *remoteProxy);
33 
34     void SetUp();
35     void TearDown();
36 };
37 
SetUpTestCase(void)38 void ChildProcessCapiTest::SetUpTestCase(void)
39 {}
40 
TearDownTestCase(void)41 void ChildProcessCapiTest::TearDownTestCase(void)
42 {}
43 
SetUp(void)44 void ChildProcessCapiTest::SetUp(void)
45 {}
46 
TearDown(void)47 void ChildProcessCapiTest::TearDown(void)
48 {}
49 
OnNativeChildProcessStarted(int errCode,OHIPCRemoteProxy * remoteProxy)50 void ChildProcessCapiTest::OnNativeChildProcessStarted(int errCode, OHIPCRemoteProxy *remoteProxy)
51 {
52 }
53 
54 /**
55  * @tc.number: OH_Ability_CreateNativeChildProcess_001
56  * @tc.desc: Test API OH_Ability_CreateNativeChildProcess works
57  * @tc.type: FUNC
58  */
59 HWTEST_F(ChildProcessCapiTest, OH_Ability_CreateNativeChildProcess_001, TestSize.Level0)
60 {
61     GTEST_LOG_(INFO) << "OH_Ability_CreateNativeChildProcess_001 begin";
62     int ret = OH_Ability_CreateNativeChildProcess(nullptr, ChildProcessCapiTest::OnNativeChildProcessStarted);
63     EXPECT_EQ(ret, NCP_ERR_INVALID_PARAM);
64 
65     ret = OH_Ability_CreateNativeChildProcess("test.so", nullptr);
66     EXPECT_EQ(ret, NCP_ERR_INVALID_PARAM);
67 
68     ret = OH_Ability_CreateNativeChildProcess("test.so", ChildProcessCapiTest::OnNativeChildProcessStarted);
69     if (!AAFwk::AppUtils::GetInstance().IsMultiProcessModel()) {
70         EXPECT_EQ(ret, NCP_ERR_SERVICE_ERROR);
71         return;
72     } else if (!AAFwk::AppUtils::GetInstance().IsSupportNativeChildProcess()) {
73         EXPECT_EQ(ret, NCP_ERR_MULTI_PROCESS_DISABLED);
74         return;
75     }
76 
77     GTEST_LOG_(INFO) << "OH_Ability_CreateNativeChildProcess return " << ret;
78     EXPECT_NE(ret, NCP_ERR_NOT_SUPPORTED);
79 }
80 
81 /**
82  * @tc.number: OH_Ability_StartNativeChildProcess_001
83  * @tc.desc: Test API OH_Ability_StartNativeChildProcess_001 works
84  * @tc.type: FUNC
85  */
86 HWTEST_F(ChildProcessCapiTest, OH_Ability_StartNativeChildProcess_001, TestSize.Level0)
87 {
88     GTEST_LOG_(INFO) << "OH_Ability_StartNativeChildProcess_001 begin";
89     NativeChildProcess_Args args;
90     NativeChildProcess_Options options;
91     int32_t pid = 0;
92     auto ret = OH_Ability_StartNativeChildProcess(nullptr, args, options, &pid);
93     EXPECT_EQ(ret, NCP_ERR_INVALID_PARAM);
94     GTEST_LOG_(INFO) << "OH_Ability_StartNativeChildProcess_001 begin";
95 }
96 
97 /**
98  * @tc.number: OH_Ability_GetCurrentChildProcessArgs_001
99  * @tc.desc: Test API OH_Ability_GetCurrentChildProcessArgs_001 works
100  * @tc.type: FUNC
101  */
102 HWTEST_F(ChildProcessCapiTest, OH_Ability_GetCurrentChildProcessArgs_001, TestSize.Level0)
103 {
104     GTEST_LOG_(INFO) << "OH_Ability_GetCurrentChildProcessArgs_001 begin";
105     EXPECT_EQ(OH_Ability_GetCurrentChildProcessArgs(), nullptr);
106     NativeChildProcess_Args args = { 0 };
107     ChildProcessArgsManager::GetInstance().SetChildProcessArgs(args);
108     EXPECT_NE(OH_Ability_GetCurrentChildProcessArgs(), nullptr);
109     GTEST_LOG_(INFO) << "OH_Ability_GetCurrentChildProcessArgs_001 end";
110 }
111 }  // namespace AbilityRuntime
112 }  // namespace OHOS
113